Calculation 2Time
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U SubmitStatus
Description
Given a positive integer n, your task is to calculate the sum of the positive integers less than N which was not coprime t o N. A is said to being coprime to B if A, B share no common positive divisors except 1.
Input
For 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.
Output
For each test case, you should print the sum of module 1000000007 in a line.
Sample Input
340
Sample Output
02
Simple translation:Enter an n, which is less than N and does not match the number of n coprime with the value of modulo 1000000007.
Problem Solving Ideas:Euler function, the sum of the number of less than N and n coprime is calculated, and the sum of the number minus coprime is obtained, and the sum of the number is not coprime.
Code:
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 Const intMod=1000000007;6 intMain ()7 {8 intN;9 while(SCANF ("%d", &n)!=eof&&N)Ten { One Long LongTemp=n,eular=1; A Long LongAns= (temp* (temp+1)/2)%MoD; - for(intI=2; i*i<=temp;i++) - if(temp%i==0) the { -Temp/=i; -eular*=i-1; - while(temp%i==0) + { -Temp/=i; +eular*=i; A } at } - if(temp>1) eular*=temp-1; -eular%=MoD; -temp=N; - Long LongW= (eular*temp/2)%MoD; -ans-=W; inans-=N; - while(ans<0) ans+=MoD; toprintf"%lld\n", ans); + } - return 0; the}Calculation 2
HDU3501 calculation 2 (Euler function)