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.
try to express this through algo pseudocode.
1. find the gcds :-
#include<bits/stdc++.h>usingnamespacestd;#define ll long long intset<int>gcds;llans=0;intmain(){lln,f,number;cin>>n>>f;while(n--){cin>>number;gcds.insert(__gcd(number,f));}
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;
if(gcd%(f/i) == 0)
flag2 = false;
}
if(flag1)
ans += 1;
if(flag2)
ans += 1;
}
}
cout << ans << endl;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Unfriendly Numbers
You are viewing a single comment's thread. Return to all comments →
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; }