题目:求出小于N的与N不互质的数的和。
思路:小于N的与N互质的数的和为eular(n)*n/2
代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
const LL MOD=1000000007;
LL phi(LL n){
LL res=n;
for(LL i=2;i*i<=n;i++)
if(n%i==0){
res=res-res/i;
while(n%i==0){
n/=i;
}
}
if(n>1)
res=res-res/n;
return res;
}
int main(){
LL n;
while(~scanf("%lld",&n)){
if(!n)
break;
LL ans=(n*(n+1)/2-n)%MOD;
ans-=(phi(n)*n)/2%MOD;
ans=(ans+MOD)%MOD;
printf("%lld\n",ans);
}
return 0;
}