Deciphering Password (积性函数+唯一分解定理+质因数分解)

Xiaoming has just come up with a new way for encryption, by calculating the key from a publicly viewable number in the following way: 
Let the public key N = A B, where 1 <= A, B <= 1000000, and a 0, a 1, a 2, …, a k-1be the factors of N, then the private key M is calculated by summing the cube of number of factors of all ais. For example, if A is 2 and B is 3, then N = A B = 8, a0 = 1, a 1 = 2, a 2 = 4, a 3 = 8, so the value of M is 1 + 8 + 27 + 64 = 100. 
However, contrary to what Xiaoming believes, this encryption scheme is extremely vulnerable. Can you write a program to prove it? 

Input

There are multiple test cases in the input file. Each test case starts with two integers A, and B. (1 <= A, B <= 1000000). Input ends with End-of-File. 
Note: There are about 50000 test cases in the input file. Please optimize your algorithm to ensure that it can finish within the given time limit. 

Output

For each test case, output the value of M (mod 10007) in the format as indicated in the sample output. 

Sample Input

2 2
1 1
4 7

Sample Output

Case 1: 36
Case 2: 1
Case 3: 4393

     题意:N=A^B,求N的因子的总数的立方和M

         比如:N=8,因子有1,2,4,8,共四个,M=1^3+2^3+3^3+4^3

     基本思路

         先用线性欧拉筛求出A^B唯一分解的素因子指数

         再根据积性函数的性质g(m*n)=g(m)*g(n)  求出立方和M

     见下图解析: 

 本题在唯一分解时只对A分解,因为B是幂,所以只要对A进行了唯一分解,求出素因子指数,再乘以B即可

    

    代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=100005;
int prime[maxn];
bool isPrime[maxn];
int cnt=0;
//线性欧拉筛 
void Init()
{
	for(int i=2;i<maxn;i++)
	{
		if(!isPrime[i]) prime[cnt++]=i;
		for(int j=0;j<cnt&&(ll)i*prime[j]<maxn;j++)
		{
			isPrime[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
}
int main()
{
	Init();
	ll res[10005];
	ll a,b;
	int p=1;
	while(~scanf("%lld%lld",&a,&b))
	{
		int t=0;
		memset(res,0,sizeof(res));
		//求唯一分解的素因子的指数 
		for(int i=0;i<cnt&&prime[i]*prime[i]<=a;i++)//一定要有这个条件 prime[i]<=a
	    {
	    	if(a%prime[i]==0)
	    	{
	    		a/=prime[i];
	    		res[t]++;
	    		while(a%prime[i]==0)
	    		{
	    			a/=prime[i];
	    			res[t]++;
				}
				t++;
			}
		}
		if(a>1)
		{
			res[t++]++;
		}
		//积性函数+质因数分解 
		ll tmp=1;
		ll ans=1;
		for(int i=0;i<t;i++)
		{
			tmp=(res[i]*b+1)*(res[i]*b+2)/2;
			tmp%=10007;
			tmp=tmp*tmp%10007;
			ans=ans*tmp%10007; 
		}
		printf("Case %d: %lld\n",p++,ans);
	}
	
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ksuper&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值