Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define N ((int)6e4 + 5)
- #define MOD ((int)1e9 + 7)
- #define MAX ((int)1e9 + 7)
- #define MAXL ((ll)1e18 + 7)
- #define MAXP ((int)1e3 + 7)
- #define thr 1e-8
- #define pi acos(-1) /// pi = acos ( -1 )
- #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
- #define endl "\n"
- using namespace std;
- int isPrime[N/32 + 2];
- bool IsPrime(int num) /// returns 1 for prime
- {
- if(num == 2) return 1;
- if((num & 1) == 0) return 0;
- int idx = num >> 5 , bit = num & 31;
- if( ( isPrime[idx] & (1<<bit) ) != 0 ) return 0;
- else return 1;
- }
- vector < int > Sieve(int n)
- {
- for(int i = 3; i * i <= n ; i += 2){
- if(IsPrime(i)){
- for(int j = i * i ; j <= n ; j += i<<1){
- int idx = j >> 5 , bit = j & 31;
- isPrime[idx] = isPrime[idx] | (1<<bit);
- }
- }
- }
- vector < int > prime;
- prime.push_back(2);
- for(int i = 3 ; i <= n ; i += 2){
- if(IsPrime(i)) prime.push_back(i);
- }
- return prime;
- }
- int NearestPowerOfTwo(int n)
- {
- while(1){
- if( (n & (n-1)) == 0 ) return n; /// power of two
- n++;
- }
- }
- int main()
- {
- /// problem: https://codeforces.com/problemset/problem/1062/B
- vector < int > prime = Sieve(1e6);
- int n;
- cin>>n;
- vector < pair < int , int > > vec;
- for(int p:prime){
- if(n % p == 0){
- int cnt = 0;
- while(n % p == 0){
- n /= p;
- cnt++;
- }
- vec.push_back({p , cnt});
- }
- }
- int ans = 1;
- bool multiply = 0;
- int minPowerOfTwo = 777 , maxPowerOfTwo = -1;
- for(auto p:vec){
- ans *= p.first;
- int cnt = p.second;
- int nearestPowerOfTwo = NearestPowerOfTwo(cnt);
- minPowerOfTwo = min(minPowerOfTwo , nearestPowerOfTwo);
- maxPowerOfTwo = max(maxPowerOfTwo , nearestPowerOfTwo);
- if(nearestPowerOfTwo > cnt) multiply = 1;
- }
- if(minPowerOfTwo != maxPowerOfTwo) multiply = 1;
- int opp = multiply;
- while(maxPowerOfTwo > 1){
- opp++;
- maxPowerOfTwo /= 2;
- }
- cout<<ans<<" "<<opp<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement