https://vjudge.net/problem/1221709/origin
解题过程有点曲折,我不赘述了,可以看CF的题解
讲几个重要的点:
1.可以用埃式筛法预处理出p[i]表示i个最小或者最大质因数(自由选择),然后分解质因数的难度就会降到logn
2.利用模板中的那片代码,可以预求出fac[1~n]的逆元,通过这种方法,就可以O(1)求出mod p ,(i,j<=n)爽极了
代码
//Problem:
//Date:
//Skill:
//Bug:
/Definations/
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define F(i,a,b) for(int i=a;i<=int(b);++i)
#define F2(i,a,b) for(int i=a;i>=int(b);--i)
#define RE(i,n) for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
//输入输出
//#define INC(c) do{scanf("%c",&c);}while(isspace(c))
//#define ON cout<<endl
#define PII pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
Options//
typedef long long ll;
//#define stdcpph
#define CPP_IO
#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
Basic Functions//
template<typename INint>
inline void IN(INint &x)
{
x = 0; int f = 1; char c; cin.get(c);
while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
x *= f;
}
template<typename INint>
inline void OUT(INint x)
{
if (x > 9)OUT(x / 10); cout.put(x % 10 + '0');
}
Added Functions//
const int maxn = int(1e6+4);
const int maxnum = 25;
ll p[maxn];
ll po[maxn];
ll C[maxn][maxnum];
ll fac[maxn+maxnum], inv_fac[maxn+maxnum];
ll mod = 1e9 + 7;
void add(ll &a, const ll &b )
{
a += b; if (a > mod)a -= mod;
}
void mul(ll &a, const ll b)
{
a *= b; if (a > mod)a %= mod;
}
ll qpow(ll a, ll b, ll p) //求a^bMODp
{
ll ret = 1;
while (b)
{
if (b & 1)
ret = (ret * a) % p;
a = (a * a) % p;
b >>= 1;
}
return ret;
}
求逆元//
费马小定理
ll inv(ll a, ll p) //返回a对p的逆元
{
return qpow(a, p - 2, p);
}
void init(ll n)
{
p[1] = 0;
for (ll i = 2; i*i <= n; ++i)
{
if (!p[i])
{
for (ll j = i; j <= n; j += i)
{
p[j] = i;
}
}
}
po[0] = 1;
RE2(i, n)
{
po[i] = (po[i - 1] << 1) % mod;
}
fac[0] = 1;
for (ll i = 1; i < maxn + maxnum; i++) {
fac[i] = fac[i - 1] * i %mod;
}
inv_fac[maxn + maxnum - 1] = qpow(fac[maxn + maxnum - 1], mod - 2,mod);
for (ll i = maxn + maxnum - 2; i >= 0; i--) {
inv_fac[i] = inv_fac[i + 1] * (i + 1) % mod;
}
}
ll solve(ll x, ll y)
{
vector<ll>v;
while (x!=1)
{
ll mm = p[x];
if (mm)
{
int tm(0);
while (x%mm == 0)
{
++tm; x /= mm;
}
v.push_back(tm);
}
else
{
v.push_back(1);
x = 1;
}
}
ll ans(1);
for (auto p : v)
{
//ll inc = po[y - 1];
ll inc = 1;
//mul(inc, po[y - 1]);
mul(inc, fac[y + p - 1]);
mul(inc, inv_fac[p]);
mul(inc, inv_fac[y - 1]);
/*add(ans, inc);*/
mul(ans, inc);
}
mul(ans, po[y - 1]);
//mul(ans, po[y - 1]);
//mul(ans, inv_fac[y - 1]);
cout << ans << endl;
return 1;
}
Code/
int main()
{
//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
int T(1), times(0);
#ifdef CPP_IO// CPP_IO
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> T;
#else
//IN(T);
#endif
/
init(1000000 + 2);
while (++times, T--)
{
ll x, y; cin >> x >> y;
solve(x, y);
}
///
return 0;
}