Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. #pragma GCC optimize("O3")
  6.  
  7. using namespace std;
  8. using namespace __gnu_pbds;
  9.  
  10. #define int long long
  11. #define double long double
  12. #define _ << ' ' <<
  13. #define For(i,z) for(int32_t i=0;i<(z);i++)
  14. #define sqr(a) ((a)*(a))
  15.  
  16. #define pii pair<int, int>
  17. #define f first
  18. #define s second
  19.  
  20. template<typename T>
  21. using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  22.  
  23. template<typename T, typename K> inline void umax(T &a, K b) { a = max(a, (T)b); }
  24. template<typename T, typename K> inline void umin(T &a, K b) { a = min(a, (T)b); }
  25.  
  26. const int32_t N = (1<<20);
  27. const int32_t M = 20010;
  28. //const int INF = 1e16 + 10;
  29. const double EPS = 1e-2;
  30. const int II = 1e9 + 10;
  31. const int MOD = 1e9+9;
  32. //const int AMOD = 99194853094755497;
  33. bool bad[N];
  34. vector <int> prime;
  35. void resh() {
  36.     for (int i = 2; i < N; i++) {
  37.         if (bad[i] == false) {
  38.             prime.push_back(i);
  39.             for (int j = i * i; j < N; j += i)
  40.                 bad[j] = true;
  41.         }
  42.     }
  43. }
  44.  
  45. vector <pair<int, vector<int> > > lay2;
  46. void ff() {
  47.     lay2.resize(prime.size()-1);
  48.     For (i, prime.size() - 1) {
  49.         lay2[i].f = prime[i] * prime[i+1];
  50.         lay2[i].s.push_back(prime[i]);
  51.         lay2[i].s.push_back(prime[i+1]);
  52.     }
  53. }
  54.  
  55.  
  56. string nums = "0123456789abcdef";
  57.  
  58. long long mul(long long a, long long b, long long m){
  59.     if(b==1)
  60.         return a;
  61.     if(b%2==0){
  62.         long long t = mul(a, b/2, m);
  63.         return (2 * t) % m;
  64.     }
  65.     return (mul(a, b-1, m) + a) % m;
  66. }
  67.  
  68. long long pows(long long a, long long b, long long m){
  69.     if(b==0)
  70.         return 1;
  71.     if(b%2==0){
  72.         long long t = pows(a, b/2, m);
  73.         return mul(t , t, m) % m;
  74.     }
  75.     return ( mul(pows(a, b-1, m) , a, m)) % m;
  76. }
  77.  
  78. bool isprime(long long x){
  79.     if(x == 2)
  80.         return true;
  81.     srand(time(NULL));
  82.     for(int i=0;i<20;i++){
  83.         long long a = (rand() % (x - 2)) + 2;
  84.         if (__gcd(a, x) != 1)
  85.             return false;
  86.         if( pows(a, x-1, x) != 1)
  87.             return false;
  88.     }
  89.     return true;
  90. }
  91.  
  92. string conv(int ch) {
  93.     string s;
  94.     while (ch) {
  95.         s.push_back(nums[ch%16LL]);
  96.         ch /= 16LL;
  97.     }
  98.     reverse(s.begin(), s.end());
  99.     return s;
  100. }
  101.  
  102. int32_t main() {
  103.     //freopen("input.txt", "r", stdin);
  104.     //freopen("output.txt", "w", stdout);
  105.     ios_base::sync_with_stdio(false);
  106.     cin.tie(0); cout.tie(0);
  107.     srand(time(NULL));
  108.     prime.reserve(N);
  109.  
  110.     int n, k;
  111.     cin >> n >> k;
  112.     string s; cin >> s;
  113.     int ch = 0, mn = 1;
  114.     for (int i = s.size()-1; i >= 0; i--) {
  115.         ch += nums.find(s[i]) * mn;
  116.         mn *= 16LL;
  117.     }
  118.  
  119.     if (k == 2) {
  120.         for (int i = sqrt(ch); ; i++)
  121.             if (ch % i == 0 && ch != i * i &&
  122.                 isprime(i) && isprime(ch/i)) {
  123.                 cout << conv(i) << '\n';
  124.                 cout << conv(ch / i);
  125.                 return 0;
  126.             }
  127.         cout << "CHLEN\n";
  128.         return 0;
  129.     }
  130.  
  131.     resh();
  132.     ff();
  133.     for (auto &i : lay2) {
  134.         for (auto &j : lay2) {
  135.             if (i.f * j.f != ch) continue;
  136.             for (auto &z : i.s)
  137.                 cout << conv(z) << '\n';
  138.             for (auto &z : j.s)
  139.                 cout << conv(z) << '\n';
  140.             return 0;
  141.         }
  142.  
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement