首页 > 代码库 > HDU——T3501 Calculation 2
HDU——T3501 Calculation 2
http://acm.hdu.edu.cn/showproblem.php?pid=3501
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4548 Accepted Submission(s): 1878
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
340
Sample Output
02
Author
GTmac
Source
2010 ACM-ICPC Multi-University Training Contest(7)——Host by HIT
欧拉函数得和==phi(n)*n/2;
md 还是见识少。。
1 #include <algorithm> 2 #include <cstdio> 3 4 using namespace std; 5 6 #define LL long long 7 const LL mod(1000000007); 8 const LL N(1000000000+5); 9 LL x;10 11 LL phi(LL x)12 {13 LL ret=1;14 for(LL i=2;i*i<=x;i++)15 if(x%i==0)16 {17 x/=i;18 ret*=i-1;19 for(;x%i==0;)20 ret*=i,x/=i;21 }22 if(x>1) ret*=x-1;23 return ret;24 }25 26 int main()27 {28 for(;scanf("%lld",&x)&&x;)29 {30 LL zz=(x-1)*x>>1;31 printf("%lld\n",(zz-(x*phi(x)>>1))%mod);32 }33 return 0;34 }
HDU——T3501 Calculation 2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。