Calculation 2
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2548 Accepted Submission (s): 1064
problem DescriptionGiven A positive integer n, your task is to calculate the sum of the positive integers less than N which was not copri Me to N. A is said to being coprime to B if A, B share no common positive divisors except 1.
Inputfor each test case, the There is a line containing a positive integer N (1≤n≤1000000000). A line containing a single 0 follows the last test case.
Outputfor each test case, you should print the sum of module 1000000007 in a line.
Sample Input
340
Sample Output
02
Test Instructions: All and n is not Inma, and all are less than N. All are less than N and with n is non-Inma and = all and of all less than n-all and the number of n coprime less than n All and the Inma of n are less than N and:
1. Euler function can be used to calculate the number of n coprime
2. If M and n coprime are known, then n-m also with n coprime The specific code is as follows:
#include <stdio.h> #define MOD 1000000007__int64 eular (__int64 N)//Euler function template {__int64 res=n,i;for (i=2;i*i<= n;i++) {if (n%i==0) res=res/i* (i-1);//Division is first to prevent overflow of intermediate data while (n%i==0) n/=i;} if (n>1) res=res/n* (n-1);//guaranteed x must be a prime return res;} int main () {__int64 n,ans;while (scanf ("%i64d", &n) &&n) {ans=n* (n-1)/2;//Find all positive integers less than N and printf ("%i64d\n", ( Ans-n*eular (n)/2)%mod);} N*eular (n)/2 is less than N and the number of n coprime, because if M and n coprime, then n-m must also be with n coprime return 0;}
Hdoj 3501 Calculation 2 (Euler function expansion--non-Inma and)