Advertisement
Guest User

10139-uva

a guest
Oct 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. const int MX = 100000;
  7. bitset<MX> bs;
  8. vector<int> primes ;
  9. map<int,int> number_factors;
  10.  
  11.  
  12. void sieve()
  13. {
  14.     bs.set();
  15.     bs[0]=bs[1]=0;
  16.     for(ll i=2;i<MX+1;i++)
  17.         if(bs[i])
  18.         {
  19.             for(ll j=i*i;j<MX;j+=i) bs[j] = 0;
  20.             primes.push_back(i);
  21.         }
  22. }
  23.  
  24. vector<int> findPrimes(ll N)
  25. {
  26.     vector<int> factors;
  27.     ll idx = 0 , pf = primes[0];
  28.     while(pf*pf<=N)
  29.     {
  30.         while(N%pf==0)
  31.         {
  32.             N/=pf;
  33.             number_factors[pf]++;
  34.         }
  35.         pf=primes[++idx];
  36.     }
  37.     if(N!=1)number_factors[N]++;
  38.     return factors;
  39. }
  40.  
  41. ll get_power(ll n, ll p)
  42. {
  43.     int res =0;
  44.     for(ll i=p;i<=n;i*=p)
  45.         res+=n/i;
  46.     return res;
  47. }
  48.  
  49. int main()
  50. {
  51.     freopen("input.txt","r",stdin);
  52.     freopen("output.txt","w",stdout);
  53.     long long n,m;
  54.     sieve();
  55.     while(cin>>n>>m)
  56.     {
  57.         bool verif = true;
  58.         if(m>n){
  59.             findPrimes(m);
  60.             for(auto &it:number_factors)
  61.             {
  62.                 if(get_power(n,it.first)<it.second)
  63.                 {
  64.                     verif = false;
  65.                     break;
  66.                 }
  67.             }
  68.             number_factors.clear();
  69.         }
  70.         if(verif)
  71.             cout<<m<<" divides "<<n<<"!\n";
  72.         else
  73.             cout<<m<<" does not divide "<<n<<"!\n";
  74.     }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement