+ 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); }
10 odpowiedzi
+ 7
Make you understand it? Sorry i run out of spells!… ~_~
+ 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?)
+ 2
@Catalin btw, out of curiosity, can you confirm what the set H is in the initial question? ( in english, or with an example😆)
+ 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.
+ 2
@Catalin Ok that makes sense. Thanks!
+ 1
well I don't even know what auto& it:{2,3,5} is, that's the main problem
+ 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...
+ 1
'auto & it : {2,3,5}' means "for each value in {2,3,5}"
+ 1
thanks @ifl, could you give me a few more details about how that works? like what "auto" and "&" are?
+ 1
thanks @ifl ,you really helped me :)