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 Description Given A positive integer N, your task is to calculate the sum of the positive integers less than N whi CH is not coprime to N. A is said to being coprime to B if A, B share no common positive divisors except 1.
Input for each test case, there was 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 title meaning: The sum of the number of n coprime, or N, of a number less than or equal to. Euler function Extension: The number of less than or equal to N (n > 1), and the sum of n coprime euler[n] * n/2. Code:
Idea: An extension of the Euler function: a number less than or equal to N, and the sum of the number of n coprime: Euler (x) * X/2. (n>1)
#include <cstdio>
#include <cstring>
#include <cmath>
#define LL Long Long
#define MOD 1000000007
using namespace std;
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 n;
while (scanf ("%lld", &n), N)
{
LL ans = n * (n+1)/2;
Ans = Ans-euler (n) * N/2;
printf ("%lld\n", (ans-n)%mod);
}
return 0;
}