hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4285字,纯文字阅读大概需要7分钟。
内容图文
![hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)](/upload/InfoBanner/zyjiaocheng/1106/34958081de504774bcb30133cea376bd.jpg)
Deciphering Password
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2357 Accepted Submission(s):
670
Let the public key N = AB, where 1 <= A, B <= 1000000, and a0, a1, a2, …, ak-1 be 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 = AB = 8, a0 = 1, a1 = 2, a2 = 4, a3 = 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?
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.
![技术分享图片](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D124/sign=ae84eec8b4fd5266a32b38169f189799/f703738da97739129c546742fa198618367ae2a7.jpg)
#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> #include<string> #include<vector> #include<iostream> #include<cstring> #define inf 0x3f3f3f3f usingnamespace std; #define ll long long constint p=10007; constint maxx=1e6+5; ll a,b; int prime[maxx]; bool vis[maxx]; int cnt; void init()///欧拉筛{ cnt=0; memset(vis,true,sizeof(vis)); vis[0]=vis[1]=false; for(int i=2;i<=maxx;i++) { if(vis[i]) prime[cnt++]=i; for(int j=0;j<cnt && prime[j]*i<=maxx;j++) { vis[ i*prime[j] ]=false; if( i%prime[j]==0 ) break;///prime[j]必定是prime[j]*i和i的最小质因子 } } } ll sum(ll n)///立方和公式{ return ( (n*n+n)/2 )%p * ( (n*n+n)/2 )%p; } int main() { init(); int x=0; while(scanf("%lld%lld",&a,&b)!=EOF) { ll ans=1; if(vis[a])//a是素数,则直接求,节省时间 ans=sum(1+b); else {//prime[i]*prime[i]<=a;不加就会超时,大素数的因子一般只有一个,没必要一个一个找,也可以改成!vis[a],都是避免多次循环找大素数for(int i=0; i<cnt && prime[i]*prime[i]<=a; i++) { int num=0; if(a==1) break; while(a%prime[i]==0) { a=a/prime[i]; num++; } if(num!=0) { ans*=sum(num*b+1);//积性函数 ans%=p; } } if(a!=1)///应对大素数的情况 { ans*=sum(b+1); ans%=p; } } printf("Case %d: %lld\n",++x,ans%p); } return0; } /* 手撸36=2^2 * 3^2 ans=(1^3 + 2^3 +3^3)^2=1296 36的因子有 1 2 3 4 6 9 12 18 36 对应的因子数 1 2 2 3 4 3 6 6 9 累加后也是1296 */
Deciphering Password
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2357 Accepted Submission(s):
670
Let the public key N = AB, where 1 <= A, B <= 1000000, and a0, a1, a2, …, ak-1 be 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 = AB = 8, a0 = 1, a1 = 2, a2 = 4, a3 = 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?
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.
原文:https://www.cnblogs.com/shoulinniao/p/10356459.html
内容总结
以上是互联网集市为您收集整理的hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)全部内容,希望文章能够帮你解决hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。