Mephistopheles_

Another problem about dividing numbers (Cf)

Jun 29th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. //https://codeforces.com/contest/1538/problem/D
  2.  
  3.  
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define forx(x1,y1) for( unsigned long long x1=0;x1<y1;++x1)
  7. #define INF 1e9
  8. #define all(x2) begin(x2),end(x2)
  9. using ll= double;
  10. using ull=unsigned long long;
  11. vector<ull>v;
  12. map<ull,ull>m;
  13. ull gcd (ull a, ull b) {
  14.     return b ? gcd (b, a % b) : a;
  15. }
  16. void f(){
  17.     v.push_back(2);
  18.     v.push_back(3);
  19.     for(ull i=5;i*i<=ull(1e9);++i){
  20.         bool b =true;
  21.         for(ull j=2;j*j<=i;++j)
  22.             if(i%j==0){
  23.                 b=false;
  24.                 break;
  25.             }
  26.         if(b)
  27.             v.push_back(i);
  28.     }
  29. }
  30. ull g(ull x){
  31.     ull kmax=0;
  32.     for(ull& i:v){
  33.         while(x%i==0){
  34.             ++m[i];
  35.             x/=i;
  36.         }
  37.         if(x==1)
  38.             break;
  39.     }
  40.     for(auto&[_,p]:m){
  41.         kmax+=p;
  42.     }
  43.     m.clear();
  44.     if (x!=1)
  45.         ++kmax;
  46.     return kmax;
  47. }
  48. int main(){
  49.     ios::sync_with_stdio(false);
  50.     cin.tie();
  51.     ull t;
  52.     f();
  53.     cin>>t;
  54.     vector<string>ot;
  55.     while(t-->0){
  56.         ull a,b;
  57.         cin>>a>>b;
  58.         ull kmin,kmax;
  59.         ull de=gcd(a,b);
  60.         if(a==b)
  61.             kmin=0;
  62.         else {
  63.             if (de == a || de == b)
  64.                 kmin = 1;
  65.             else
  66.                 kmin = 2;
  67.         }
  68.         kmax=g(a);
  69.         kmax+=g(b);
  70.         ull k;
  71.         cin>>k;
  72.         if(a==b && k==1){
  73.             ot.emplace_back("NO");
  74.             continue;
  75.         }
  76.         if (k >= kmin && k <= kmax)
  77.             ot.emplace_back("YES");
  78.         else
  79.             ot.emplace_back("NO");
  80.     }
  81.     for(auto& i:ot)
  82.         cout<<i<<'\n';
  83. }
Advertisement
Add Comment
Please, Sign In to add comment