[Codeforces 1228C] Primes and Multiplication(数学)

把x分解质因数,枚举因子和指数看出现多少次

#include <iostream>
#include <queue>
#include <cstring>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
typedef long long LL;
 
const LL Mod = (LL)1e9+7;
LL p[41622];
LL tot = 0;

void calc(LL n) {
	for (LL i = 2; i <= sqrt(n+0.5); i++) 
	 if (n%i == 0) {
	 	p[++tot] = i;
	 	while(n%i == 0) {
	 		n /= i;
		}
	 }
	 if (n > 1) {
	 	p[++tot] = n;
	 }
}

LL mul(LL a,LL b){
	LL ans = 0;
   a = a%Mod;
   for ( ; b; b>>=1,a = (a+a)%Mod)
     if (b&1) ans = (ans+a)%Mod;
   return ans;
}

LL qpow(LL a,LL b) {
	LL ans = 1;
	for ( ; b; b>>=1,a = mul(a,a)) 
	  if (b&1) ans = mul(ans,a);
	return ans;
}

int main() {
	long long xx,nn;
	LL x,n;
	cin >> xx >> nn;
	x=xx; n = nn;
	calc(x);

	LL ans = 1;
	for (LL i = 1; i <= tot; i++) {
     unsigned long long t;
	  for (unsigned long long j = p[i]; j <= n; j = t) {
	  	if (1.0*n/p[i] < j) {
	  		ans = (ans*qpow(j,n/j))%Mod;
         break;
		}
	  	t = j*p[i];
        
	  	ans = (ans*qpow(j,n/j-n/t))%Mod;
	  }
    }
    cout << (long long)ans;
    return 0;
}

 

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

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

Let ?(?,?) be the maximum possible integer ?? where ? is an integer such that ? is divisible by ??. For example:

?(45,3)=9 (45 is divisible by 32=9 but not divisible by 33=27),
?(63,7)=7 (63 is divisible by 71=7 but not divisible by 72=49).
Let ?(?,?) be the product of ?(?,?) for all ? in ?????(?). For example:

?(30,70)=?(70,2)⋅?(70,3)⋅?(70,5)=21⋅30⋅51=10,
?(525,63)=?(63,3)⋅?(63,5)⋅?(63,7)=32⋅50⋅71=63.
You have integers ? and ?. Calculate ?(?,1)⋅?(?,2)⋅…⋅?(?,?)mod(109+7).

Input
The only line contains integers ? and ? (2≤?≤109, 1≤?≤1018) — the numbers used in formula.

Output
Print the answer.

Examples
inputCopy
10 2
outputCopy
2

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值