hdoj 3501
2016-04-05 18:52
323 查看
Calculation 2
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3295 Accepted Submission(s): 1360
Problem Description
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.
Input
For each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.
Output
For each test case, you should print the sum module 1000000007 in a line.
Sample Input
3
4
0
Sample Output
0
2
Author
GTmac
欧拉公式的引伸:小于或等于n的数中,与n互质的数的总和为:φ(x) * x / 2。(n>=1);
代码:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3295 Accepted Submission(s): 1360
Problem Description
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.
Input
For each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.
Output
For each test case, you should print the sum module 1000000007 in a line.
Sample Input
3
4
0
Sample Output
0
2
Author
GTmac
欧拉公式的引伸:小于或等于n的数中,与n互质的数的总和为:φ(x) * x / 2。(n>=1);
代码:
#include<cstdio> #include<cstring> #include<queue> #include<vector> #include<algorithm> using namespace std; #define LL long long #define MOD 1000000007 LL euler(LL n) { LL i; LL eu=n; for(i=2;i*i<=n;i++) { if(n%i==0) { eu=eu*(i-1)/i; while(n%i==0) n/=i; } } if(n>1) eu=eu*(n-1)/n; return eu; } int main() { LL t; while (scanf("%lld",&t),t) { LL s=0; s+=t*(t-1)/2-euler(t)*t/2; printf("%lld\n",s%MOD); } return 0; }
相关文章推荐
- 0405第四章读后感
- 错误提示: An App ID with identifier "*****" is not avaliable. Please enter a different string.
- 四则运算法则在Java中的实现
- 布局动画 LayoutAnimation
- 第6周项目2(1)画出变量占用的内存及值得变化
- 时间类 (内联成员函数)
- 第五周项目1-三角形类雏形(2)
- FragmentPagerAdapter与FragmentStatePagerAdapter区别
- android meterdesign 动画 (二)
- java中list、set、map区别(转)
- 海量数据处理
- Framework启动流程(1) - init进程启动过程
- matlab自带各种分类器的使用示例
- 单机session共享问题的解决
- git的使用 - 团队开发
- Maven教程
- 第6周项目1—IT妹子类的设计
- The 7th Zhejiang Provincial Collegiate Programming Contest
- Tixml主页上给的一个遍历方法
- Pku oj 2159 Ancient Cipher(字符串)