Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define double long double
  7.  
  8. int n;
  9.  
  10. void write(int n) {
  11.     string ans;
  12.     while (n) {
  13.         int d = n % 16;
  14.         if (d < 10) ans.push_back((char)(d + '0'));
  15.         else ans.push_back((char)(d - 10 + 'a'));
  16.         n /= 16;
  17.     }
  18.     reverse(ans.begin(), ans.end());
  19.     cout << ans << endl;
  20. }
  21.  
  22. int read(const string& s) {
  23.     int res = 0;
  24.     for (auto& i : s) {
  25.         res *= 16;
  26.         if (i >= '0' && i <= '9') res += (int)i - '0';
  27.         else res += (int)i - 'a' + 10;
  28.     }
  29.     return res;
  30. }
  31.  
  32. void solve() {
  33.     vector<int> d;
  34.     for (int k = 2; k * k <= n; ++k) {
  35.         if (n % k == 0) {
  36.             n /= k;
  37.             d.push_back(k);
  38.         }
  39.     }
  40.     if (n > 1) d.push_back(n);
  41.     for (auto& i : d) write(i);
  42.     exit(0);
  43. }
  44.  
  45. signed main() {
  46.     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  47.     cout << fixed << setprecision(20);
  48. #ifdef _DEBUG
  49.     freopen("input.txt", "r", stdin);
  50.     freopen("output.txt", "w", stdout);
  51. #endif
  52.     int b, k;
  53.     string s;
  54.     cin >> b >> k;
  55.     cin >> s;
  56.     n = read(s);
  57.  
  58.     if (k == 4) solve();
  59.  
  60.     vector<int> d;
  61.     if (n % 2 == 0) {
  62.         d.push_back(2);
  63.         n /= 2;
  64.     }
  65.  
  66.     int st = max((int)(sqrt(n) - 1e6), 3LL);
  67.     if (st % 2 == 0) --st;
  68.     for (int k = st; k <= (int)(sqrt(n) + 1e6); k += 2) {
  69.         if (n % k == 0) {
  70.             d.push_back(k);
  71.             n /= k;
  72.         }
  73.         if (n == 1) break;
  74.     }
  75.     if (n > 1) d.push_back(n);
  76.  
  77.     for (auto& i : d) write(i);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement