We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Unfriendly Numbers
Unfriendly Numbers
Sort by
recency
|
19 Discussions
|
Please Login in order to post a comment
With gcd or without gcd, I can not pass last 2 test case due to timeout. Using PHP.
Full Solution in Python:
I didn't find a single proper solution or even hint in discussion, so I wrote this.
hint: If factor of f divides an unfriendly number, then factor of f also divides gcd(unfriendly number, f)
Solution in python:
Java 8
try to express this through algo pseudocode. 1. find the gcds :-
find divisors which is not the devisor of the unfriendly numbers by checking throgh the set of the gcds. for(ll i = 1 ; i*i <= f ; i++){ if(f%i==0){ bool flag1 = true,flag2 = true; for(auto gcd: gcds){ if(gcd%i == 0) flag1 = false;
} cout << ans << endl; }