The meaning of problems
https://vjudge.net/problem/CodeForces-1228C
First, start with some definitions related to:
Defined Prime (x) denotes the set of prime factors of x. For example, P R & lt I m E ( . 1 . 4 0 ) = { 2 , . 5 , . 7 }, P R & lt I m E ( . 1 . 6 . 9 ) = { . 1 . 3 }.
Definition of G ( x , P ) indicating the presence of a maximum K ∈ N *, x may be such that p ^ k divisible , then g (x, p) = p ^ k . for example:
- G (45, 3) = 9 ( 45 may be 3 ^ 2 = 9 divisible but can not be 3 ^ 3 = 27 divisible)
- G (63 is, 7) = 7 (63 is may be 7 ^ 7 = 1 divisible but can not be 7 ^ 2 = 49 divisible)
Definition of f (x, y) represents all G ( Y , P ) ( P ∈ P R & lt I m E ( X ) product) is, for example:
- f(30, 70) = g(70,2)·g(70,3)·g(70, 5) = 2^1·3^0·5^1 = 10
- f(525,63) = g(63,3)·g(63,5)·g(63,7) = 3^2·5^0·7^1 = 63
Now given two integers x and n, the Calculate F ( x , . 1 ) ⋅ F ( x , 2 ) ... F ( x , n- ) m O D ( . 1 0 ^ . 9 + . 7 values).
Thinking
First count x = 10, n = 10 in the case of
f(10,1)=1 f(10,2)=g(2,2)=2 f(10,3)=1 f(10,4)=g(4,2)=4 f(10,5)=g(5,5)=5
f(10,6)=g(6,2)=2 f(10,7)=1 f(10,8)=g(8,2)=8 f(10,9)=1 f(10,10)=g(10,5)=10
Easy to find, for the prime factors of 10 2,4,6,8,10 2,5,2 have emerged once again appeared in the 4,8, 8 appeared again. So for prime factor i, its contribution is x ^ (n / x) * x ^ (n / x / x) * x ^ (n / x / x / x) * ......
So the prime factorization of x (x can be decomposed to the root), then the contribution of each calculated quality factor.
Code
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=200005; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) ll qpow(ll a,ll b) { ll res=1; while(b) { if(b&1) res=res*a%mod; a=a*a%mod; b>>=1; } return res; } int main() { std::ios::sync_with_stdio(false); ll x,n; cin>>x>>n; ll xx=x,gx=sqrt(x); ll ans=1; for(ll i=2; i<=gx; i++) { int f=0; if(xx==1) break; while(xx%i==0&&xx!=1) { xx/=i; f=1; } if(f) { ll nn=n; while(nn) { nn/=i; ans=ans*qpow(i,nn)%mod; } } } if(xx>1) { ll nn=n,i=xx; while(nn) { nn/=i; ans=ans*qpow(i,nn)%mod; } } cout<<ans<<endl; return 0; }