Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- /****************************************
- * *
- * Using: Extended SP template *
- * Made by: Karle F. Kremen *
- * At: 5.2.16 00:41:50 ALMT *
- * For: LKSH Qualification *
- * *
- ****************************************/
- // settings
- #define FILE "good"
- #define USE_FREOPEN 1
- #define USE_LONG 1
- #define USE_IOSOPT 0
- #define INTERACT 0
- // system
- #if USE_LONG
- typedef long long ll;
- #else
- typedef int ll;
- #endif
- #if USE_LONG
- typedef unsigned long long ull;
- #else
- typedef unsigned int ull;
- #endif
- typedef short sym;
- #if INTERACT
- #define eol endl
- #else
- #define eol '\n'
- #endif
- #define pb push_back
- #define mp make_pair
- #define p(a, b) pair < a, b >
- #define sq(x) (x * x)
- #define fi first
- #define se second
- #define rm erase
- #define ins insert
- #define rev(a) reverse(a.begin(), a.end())
- #define ord(a) sort(a.begin(), a.end())
- #define rs resize
- #define sz size
- #define M3 (ll)1e3
- #define M4 (ll)1e4
- #define M5 (ll)1e5
- #define M6 (ll)1e6
- #define M7 (ll)1e7
- #define M8 (ll)1e8
- #define M9 (ll)1e9
- #define stlprint(a) \
- for(auto __LEVEL_1_STL_ITERATOR = a.begin(); __LEVEL_1_STL_ITERATOR != a.end(); __LEVEL_1_STL_ITERATOR++) \
- { \
- cout << (*__LEVEL_1_STL_ITERATOR) << ' '; \
- }
- #define stlfor(a) \
- for(auto it = a.begin(); it != a.end(); it++)
- #define die(a) \
- { \
- cout << a << endl; \
- exit(0); \
- }
- using namespace std;
- ll prm[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };
- ll bpow(ll n, ll p, ll base)
- {
- if(p == 1)
- return n % base;
- if(p == 0)
- return 1;
- if(p & 1)
- {
- return ((n % base) * (bpow(n, p - 1, base) % base)) % base;
- }
- ll tmp = bpow(n, p >> 1, base) % base;
- return (tmp * tmp) % base;
- }
- bool isPrime(ll n)
- {
- if(n < 2)
- return 0;
- for(int i = 0; i < 20; i++)
- {
- if(prm[i] == n)
- return 1;
- ll pw = bpow(prm[i], n - 1, n);
- if(pw != 1)
- return 0;
- }
- return 1;
- }
- int main()
- {
- // ios{
- #if USE_IOSOPT
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- #endif
- #if USE_FREOPEN
- freopen(FILE".in", "r", stdin);
- freopen(FILE".out", "w", stdout);
- #endif
- ll n, k;
- cin >> n >> k;
- ll kc = 0;
- if(isPrime(n))
- die(-1);
- while(1)
- {
- if(n % k == 0)
- {
- n /= k;
- kc++;
- continue;
- }
- break;
- }
- if(isPrime(n) && kc <= 1)
- die(-1);
- if(kc > 1)
- {
- cout << pow(k, kc) << ' ';
- kc = 0;
- }
- for(int i = 2; (i * i) <= n; i++)
- {
- while(n % i == 0)
- {
- n /= i;
- if(kc > 0)
- {
- cout << (i * k) << ' ';
- kc--;
- continue;
- }
- cout << i << ' ';
- }
- }
- cout << n << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment