码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3501 Calculation 2

时间:2014-08-13 10:35:25      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   java   os   io   strong   for   

Calculation 2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2135    Accepted Submission(s): 898


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
 




#include <iostream>
#include <cstdio>
using namespace std;
#define LL __int64

LL eular(LL n)   // 求欧拉函数
{
    LL i,res=n;
    for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			res=res/i*(i-1);
			while(n%i==0)
				n/=i;
		}
	}
	if(n>1)
		res=res/n*(n-1);
	return  res;
}


int main()
{
    LL n;
    while(scanf("%I64d",&n)&&n!=0)
    {
        if(n==1)
        {
            printf("0\n");
            continue;
        }
        LL k=eular(n);
		//printf("%I64d\n",k);     //  n的欧拉函数值
		//printf("%I64d\n",n*k/2);  // 小于n 且与n互质的数 之和
        printf("%I64d\n",((n-1)*n/2-n*k/2)%1000000007);  //小于n 且与n不互质的数 之和 
    }
    return 0;
}


hdu 3501 Calculation 2,布布扣,bubuko.com

hdu 3501 Calculation 2

标签:des   style   color   java   os   io   strong   for   

原文地址:http://blog.csdn.net/fyxz1314/article/details/38532109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!