+ 1

help me understand this code please

Write a function that accepts a positive integer n argument and returns a value of 1 if n belongs to the set H ={2^x⋅3^y⋅5^z | x, y, z∈N} respectively 0 otherwise. int function(int n) { for(auto& it : {2, 3, 5}) while(n % it == 0) n /= it; return (n == 1); }

2nd Jan 2017, 10:17 PM
Catalin Dervesteanu
Catalin Dervesteanu - avatar
10 odpowiedzi
+ 7
Make you understand it? Sorry i run out of spells!… ~_~
2nd Jan 2017, 10:19 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
auto is defining the type of the variable automatically, by looking at the value assigned to the variable ( a bit like 'var" in c#, maybe?)
2nd Jan 2017, 11:46 PM
ifl
ifl - avatar
+ 2
@Catalin btw, out of curiosity, can you confirm what the set H is in the initial question? ( in english, or with an example😆)
2nd Jan 2017, 11:51 PM
ifl
ifl - avatar
+ 2
I think the best I can do is giving an example function(180)=1 as 180=2^2•3^2•5^1 function(385)=0 as 385=5^1•77^1 I don't understand what you're trying to say by "in the initial question", but the set H( I hope the word "set" is used correctly as I don't know a substitute for it) is surely an important part of the problem.
3rd Jan 2017, 8:13 AM
Catalin Dervesteanu
Catalin Dervesteanu - avatar
+ 2
@Catalin Ok that makes sense. Thanks!
3rd Jan 2017, 12:45 PM
ifl
ifl - avatar
+ 1
well I don't even know what auto& it:{2,3,5} is, that's the main problem
2nd Jan 2017, 10:23 PM
Catalin Dervesteanu
Catalin Dervesteanu - avatar
+ 1
Tristan, thank you for that, but I already know the math, I don't need you to explain it, I even made a program that properly solves the problem, but the code in the description is an alternative solution witch I don't understand how it works...
2nd Jan 2017, 11:28 PM
Catalin Dervesteanu
Catalin Dervesteanu - avatar
+ 1
'auto & it : {2,3,5}' means "for each value in {2,3,5}"
2nd Jan 2017, 11:29 PM
ifl
ifl - avatar
+ 1
thanks @ifl, could you give me a few more details about how that works? like what "auto" and "&" are?
2nd Jan 2017, 11:32 PM
Catalin Dervesteanu
Catalin Dervesteanu - avatar
+ 1
thanks @ifl ,you really helped me :)
2nd Jan 2017, 11:48 PM
Catalin Dervesteanu
Catalin Dervesteanu - avatar