Advertisement
_rashed

UVA 10892

Jul 5th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. map<ll,ll> factors(ll cn) {
  9.     map<ll,ll> f;
  10.     for(ll i = 2; i * i <= cn; (i == 2 ? i++: i+=2)) {
  11.         while(cn%i == 0) {
  12.             f[i]++;
  13.             cn /= i;
  14.         }
  15.     }
  16.     if(cn > 1) {
  17.         f[cn]++;
  18.     }
  19.     return f;
  20. }
  21.  
  22. int main()
  23. {
  24.     ios_base::sync_with_stdio(false);
  25.     cin.tie(NULL);
  26.     cout.tie(NULL);
  27.     ll n;
  28.     while(true) {
  29.         cin >> n;
  30.         if(!n)
  31.             break;
  32.         vector<ll> divisors;
  33.         for(ll i = 1; i * i <= n; i++) {
  34.             if(n%i == 0) {
  35.                 divisors.push_back(i);
  36.                 if(n/i != i) {
  37.                     divisors.push_back(n/i);
  38.                 }
  39.             }
  40.         }
  41.         map<ll,ll> f = factors(n);
  42.         /*cout << "factors are: ";
  43.         for(pair<ll,ll> fp : f) {
  44.             cout << "{" << fp.first << "," << fp.second << "} ";
  45.         }
  46.         cout << "\ndivisors are: ";
  47.         for(int div : divisors) {
  48.             cout << div << " ";
  49.         }
  50.         cout << "\n";*/
  51.         ll ans = 0;
  52.         for(ll div : divisors) {
  53.             map<ll,ll> df = factors(div);
  54.             ll possible = 1;
  55.             for(pair<ll,ll> fp : f) {
  56.                 if(fp.second > df[fp.first]) {
  57.                     possible *= 2;
  58.                 }
  59.             }
  60.             ans += possible;
  61.         }
  62.         cout << n << " " << (ans+1)/2 << "\n";
  63.     }
  64.     /*int cnt = 0;
  65.     for(int i = 1; i <= 100; i++) {
  66.         for(int j = 1; j <= 100; j++) {
  67.             int g = __gcd(i,j);
  68.             if((i*j)/g == 12) {
  69.                 cout << "{" << i << "," << j << "}\n";
  70.                 cnt++;
  71.             }
  72.         }
  73.     }
  74.     cout << "cnt = " << cnt << "\n";*/
  75.     return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement