2017多校训练赛第二场 HDU 6051 (数论)——By alpc_wh
来源:互联网 发布:mac修容 编辑:程序博客网 时间:2024/06/05 03:18
If the starlight never fade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 122 Accepted Submission(s): 65
Problem Description
We will give you a non-negative integer
And we define
Now, you have to calculate the sum
Maybe the sum is too big,so you only need to output the sum after mod
Input
The first line contains only one integer
For each test case, there are a integer
Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1) and y is the sum after mod
Sample Input
35 73 112 103
Sample Output
Case #1: 210Case #2: 390Case #3: 50388
Source
2017 Multi-University Training Contest - Team 2
非常有意思的数论题,纯理论,推出结论后照抄公式计算即可。这里直接把我们学长的推导过程贴出来吧,不要盗走哦。——By alpc_wh。
两进Final、五次regional金牌……Orz……感谢大佬提供详尽题解……具体见代码,这么清楚了,我没什么好说的了:
#include<bits/stdc++.h>#define mod 1000000007#define LL long longusing namespace std;int phi(int k)//欧拉函数phi{ int i,s; s = k; for(i = 2;i * i <= k; i++) { if(k % i == 0) s = s / i * (i - 1); while(k % i == 0) k /= i; } if(k > 1) s = s / k * (k - 1); return s;}LL m,p,j;int main(){ int T_T,T; cin>>T_T;T=T_T; while(T_T--) { scanf("%I64d%I64d",&m,&p); p--; LL ans=0; int n=(int) sqrt(p); for(LL i=1;i<=n;i++) { if (p%i) continue; ans+=p/2ll*(i-1ll)*phi(p/i); if (ans>=mod) ans%=mod; if (i==1) continue; j=p/i; ans+=p/2ll*(j-1ll)*phi(p/j); if (ans>=mod) ans%=mod; } ans+=p*(p-1ll); ans%=mod; printf("Case #%d: %I64d\n",T-T_T,ans*m%mod); } return 0;}
- 2017多校训练赛第二场 HDU 6051 (数论)——By alpc_wh
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- 2017多校训练赛第二场 HDU 6052(统计+思维)
- 2017 多校训练第二场 HDU 6055 Regular polygon
- 2017 多校训练第二场 HDU 6047 Maximum Sequence
- 2017 多校训练第二场 HDU 6050 Funny Function
- 2017 多校训练第二场 HDU 6053 TrickGCD
- 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
- 2017多校训练赛第二场 HDU 6053 TrickGCD(容斥原理/莫比乌斯反演)
- (2017多校训练第一场)HDU
- (2017多校训练第一场)HDU
- (2017多校训练第一场)HDU
- (2017多校训练第三场)HDU
- (2017多校训练第三场)HDU
- 二叉树的高度/销毁一颗二叉树
- quartz定时任务调度器开发Java Product自动运行项目
- Mysql系列二 mysql语法总结
- session 共享问题
- Python爬虫知识(3)—— xpath 选择器
- 2017多校训练赛第二场 HDU 6051 (数论)——By alpc_wh
- 遇到的Mysql优化问题
- jquery表格动态增删改及取数据绑定数据完整方案
- 两个.c文件访问同一个全局变量的用法
- Mac Maven
- 实训--day19Python
- webview设置网页加载进度条和设置点击返回键
- Android基于XMPP协议之asmack源码分析
- Java 线程池艺术探索