C. Primes and Multiplication

Let's introduce some definitions that will be needed later.

Let prime(x)prime(x) be the set of prime divisors of xx. For example, prime(140)={2,5,7}prime(140)={2,5,7}, prime(169)={13}prime(169)={13}.

Let g(x,p)g(x,p) be the maximum possible integer pkpk where kk is an integer such that xx is divisible by pkpk. For example:

  • g(45,3)=9g(45,3)=9 (4545 is divisible by 32=932=9 but not divisible by 33=2733=27),
  • g(63,7)=7g(63,7)=7 (6363 is divisible by 71=771=7 but not divisible by 72=4972=49).

Let f(x,y)f(x,y) be the product of g(y,p)g(y,p) for all pp in prime(x)prime(x). For example:

  • f(30,70)=g(70,2)g(70,3)g(70,5)=213051=10f(30,70)=g(70,2)⋅g(70,3)⋅g(70,5)=21⋅30⋅51=10,
  • f(525,63)=g(63,3)g(63,5)g(63,7)=325071=63f(525,63)=g(63,3)⋅g(63,5)⋅g(63,7)=32⋅50⋅71=63.

You have integers xx and nn. Calculate f(x,1)f(x,2)f(x,n)mod(109+7)f(x,1)⋅f(x,2)⋅…⋅f(x,n)mod(109+7).

Input

The only line contains integers xx and nn (2x1092≤x≤109, 1n10181≤n≤1018) — the numbers used in formula.

Output

Print the answer.

Examples
input
Copy
10 2
output
Copy
2
input
Copy
20190929 1605
output
Copy
363165664
input
Copy
947 987654321987654321
output
Copy
593574252
Note

In the first example, f(10,1)=g(1,2)g(1,5)=1f(10,1)=g(1,2)⋅g(1,5)=1, f(10,2)=g(2,2)g(2,5)=2f(10,2)=g(2,2)⋅g(2,5)=2.

In the second example, actual value of formula is approximately 1.597101711.597⋅10171. Make sure you print the answer modulo (109+7)(109+7).

In the third example, be careful about overflow issue.

 

 直接模拟

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#define ll              long long
#define PII             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
using namespace std;
int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod =1e9+7;
const int N = 100005;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
    ll x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}
ll gcd(ll m, ll n)
{
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}
ll qpow(ll m, ll k, ll mod)
{
    ll res = 1, t = m;
    while (k)
    {
        if (k & 1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}       

ll n, x;
int main()
{
    cin >> x >> n;
    vector<ll> a;
    for (int i = 2; i <= sqrt(x); i++)
    {
        if (x % i==0)
        {
            a.push_back(i);
            while (x % i == 0)
                x /= i;
        }
    }
    if(x!=1)
        a.push_back(x);
    ll res = 1;
    for (int i = 0; i < a.size(); i++)
    {
        ll cnt=0, tmp = n;
        while (tmp)
        {
            tmp /= a[i];
            cnt+=tmp;
        }
        res = (res % mod * qpow(a[i],cnt,mod) % mod) % mod;
    }
    cout << res << endl;
    return 0;
}

 

posted @ 2020-06-08 10:33  DeaL57  阅读(137)  评论(0编辑  收藏  举报