Advertisement
MiinaMagdy

10139 - Factovisors

Mar 9th, 2023 (edited)
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. map<int, int> factorize(int x) {
  11.     map<int, int> fact_freq;
  12.     if (x == 0) return fact_freq;
  13.     while (x % 2 == 0) {
  14.         fact_freq[2]++;
  15.         x /= 2;
  16.     }
  17.     for (int i = 3; i <= sqrt(x); i += 2) {
  18.         while (x % i == 0) {
  19.             x /= i;
  20.             fact_freq[i]++;
  21.         }
  22.     }
  23.     if (x > 2) {
  24.         fact_freq[x]++;
  25.     }
  26.     return fact_freq;
  27. }
  28.  
  29. void $_$(int n, int m) {
  30.     auto fact_freq = factorize(m);
  31.     bool flag = true;
  32.     for (auto& [p, cnt] : fact_freq) {
  33.         int pow = 0;
  34.         for (ll j = p; j <= n; j = j * p) {
  35.             pow += n / j;
  36.         }
  37.         flag &= (pow >= cnt);
  38.     }
  39.     cout << m << " " << (flag ? "divides" : "does not divide") << " " << n << "!\n";
  40. }
  41.  
  42. int main() {
  43.     cin.tie(0), cin.sync_with_stdio(0);
  44.     int test = 1, n, m;
  45.     //cin >> test;
  46.     while (cin >> n >> m) $_$(n, m);
  47. }
  48.  
Tags: UVA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement