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++) \
- { \
- printf("%lld ", *__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 };
- const ll bpow(const ll &n, const ll &p, const 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;
- }
- const bool isPrime(const 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;
- scanf("%lld %lld", &n, &k);
- vector < ll > ans;
- while(1)
- {
- if(n % (k * k) != 0)
- break;
- n /= k;
- n /= k;
- ans.pb(k * k);
- }
- bool kl = (n % k == 0);
- vector < ll > pr;
- for(int i = 2; i <= ceil(sqrt(n) + 1); i++)
- {
- while(n % i == 0)
- {
- n /= i;
- pr.pb(i);
- }
- }
- if(n != 1) pr.pb(n);
- if(kl && pr.sz() == 0)
- die(-2);
- for(int i = 0; i < pr.sz(); i++)
- {
- if(kl)
- {
- ans.pb(k * pr[i]);
- kl = 0;
- }
- else
- ans.pb(pr[i]);
- }
- if(ans.sz() < 2)
- die(-1);
- stlprint(ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment