KarleFKremen

Untitled

Apr 11th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. /****************************************
  4.  *                                      *
  5.  *  Using:      Extended SP template    *
  6.  *  Made by:    Karle F. Kremen         *
  7.  *  At:         5.2.16 00:41:50 ALMT    *
  8.  *  For:        LKSH Qualification      *
  9.  *                                      *
  10.  ****************************************/
  11.  
  12. // settings
  13.     #define FILE "good"
  14.     #define USE_FREOPEN 1
  15.     #define USE_LONG 1
  16.     #define USE_IOSOPT 0
  17.     #define INTERACT 0
  18.  
  19. // system
  20.     #if USE_LONG
  21.         typedef long long ll;
  22.     #else
  23.         typedef int ll;
  24.     #endif
  25.     #if USE_LONG
  26.         typedef unsigned long long ull;
  27.     #else
  28.         typedef unsigned int ull;
  29.     #endif
  30.     typedef short sym;
  31.     #if INTERACT
  32.         #define eol endl
  33.     #else
  34.         #define eol '\n'
  35.     #endif
  36.     #define pb push_back
  37.     #define mp make_pair
  38.     #define p(a, b) pair < a, b >
  39.     #define sq(x) (x * x)
  40.     #define fi first
  41.     #define se second
  42.     #define rm erase
  43.     #define ins insert
  44.     #define rev(a) reverse(a.begin(), a.end())
  45.     #define ord(a) sort(a.begin(), a.end())
  46.     #define rs resize
  47.     #define sz size
  48.     #define M3 (ll)1e3
  49.     #define M4 (ll)1e4
  50.     #define M5 (ll)1e5
  51.     #define M6 (ll)1e6
  52.     #define M7 (ll)1e7
  53.     #define M8 (ll)1e8
  54.     #define M9 (ll)1e9
  55.     #define stlprint(a) \
  56.         for(auto __LEVEL_1_STL_ITERATOR = a.begin(); __LEVEL_1_STL_ITERATOR != a.end(); __LEVEL_1_STL_ITERATOR++) \
  57.         { \
  58.             printf("%lld ", *__LEVEL_1_STL_ITERATOR); \
  59.         }
  60.     #define stlfor(a) \
  61.         for(auto it = a.begin(); it != a.end(); it++)
  62.     #define die(a) \
  63.         { \
  64.             cout << a << endl; \
  65.             exit(0); \
  66.         }
  67.  
  68. using namespace std;
  69.  
  70. ll prm[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };
  71.  
  72. const ll bpow(const ll &n, const ll &p, const ll &base)
  73. {
  74.     if(p == 1)
  75.         return n % base;
  76.     if(p == 0)
  77.         return 1;
  78.     if(p & 1)
  79.     {
  80.         return ((n % base) * (bpow(n, p - 1, base) % base)) % base;
  81.     }
  82.     ll tmp = bpow(n, p >> 1, base) % base;
  83.     return (tmp * tmp) % base;
  84. }
  85.  
  86. const bool isPrime(const ll &n)
  87. {
  88.     if(n < 2)
  89.         return 0;
  90.     for(int i = 0; i < 20; i++)
  91.     {
  92.         if(prm[i] == n)
  93.             return 1;
  94.         ll pw = bpow(prm[i], n - 1, n);
  95.         if(pw != 1)
  96.             return 0;
  97.     }
  98.     return 1;
  99. }
  100.  
  101. int main()
  102. {
  103.     // ios{
  104.         #if USE_IOSOPT
  105.             ios_base::sync_with_stdio(false);
  106.             cin.tie(0);
  107.         #endif
  108.         #if USE_FREOPEN
  109.             freopen(FILE".in", "r", stdin);
  110.             freopen(FILE".out", "w", stdout);
  111.  
  112.         #endif
  113.     ll n, k;
  114.     scanf("%lld %lld", &n, &k);
  115.     vector < ll > ans;
  116.     while(1)
  117.     {
  118.         if(n % (k * k) != 0)
  119.             break;
  120.         n /= k;
  121.         n /= k;
  122.         ans.pb(k * k);
  123.     }
  124.     bool kl = (n % k == 0);
  125.     vector < ll > pr;
  126.     for(int i = 2; i <= ceil(sqrt(n) + 1); i++)
  127.     {
  128.         while(n % i == 0)
  129.         {
  130.             n /= i;
  131.             pr.pb(i);
  132.         }
  133.     }
  134.     if(n != 1) pr.pb(n);
  135.     if(kl && pr.sz() == 0)
  136.         die(-2);
  137.     for(int i = 0; i < pr.sz(); i++)
  138.     {
  139.         if(kl)
  140.         {
  141.             ans.pb(k * pr[i]);
  142.             kl = 0;
  143.         }
  144.         else
  145.             ans.pb(pr[i]);
  146.     }
  147.     if(ans.sz() < 2)
  148.         die(-1);
  149.     stlprint(ans);
  150. }
Advertisement
Add Comment
Please, Sign In to add comment