to
This blog starfish! ! Picking out from the OVO seniors in https://www.cnblogs.com/meowww/p/6400841.html
It CQOI2007 summed number
Too lazy to look to prove ah .... talk about it ... (from the book lyd)
int main(){
rd(n),rd(k);ans=n*k;
for(int x=1,gx;x<=n;x=gx+1){
gx=k/x?Min(k/(k/x),n):n;
ans-=(k/x)*(x+gx)*(gx-x+1)/2;
}
printf("%lld",ans);
return 0;
}
Euler function
See notes on a laptop it ...
the nature of the product as well as a function of the Euler function of some knowledge
\(\varphi(N)=N*\frac {p_1-1}{p_1}*\frac{p_2-1}{p_2}*...*\frac{p_m-1}{p_m}=\prod\limits_{质数p|N}(1-\frac1p)\)
int phi(int n){
int ans=n;
for(int i=1;i<=sqrt(n);++i)
if(!n%i){
ans=ans/i*(i-1);
while(!n%i) n/=i;
}
if(ans>1) ans=ans/n*(n-1);
}
Thought Eratosthenes sieve using a \ (O (N \, log \, N) \) is determined (N \ 2 \ sim) \ Euler function for each of the number of
void euler(int n){
for(int i=2;i<=n;++i) phi[i]=i;
for(int i=2;i<=n;++i)
if(phi[i]==i)
for(int j=i;j<=n;j+=i)
phi[j]=phi[j]/i*(i-1);
}
Thought linear screen \ (O (N) \) derived \ (2 \ sim N \) Euler function for each of the number of
int v[N],prime[N],phi[N];
void euler(int n){
memset(v,0,sizeof(v));
m=0;
for(int i=2;i<=n;++i){
if(!v[i]) v[i]=i,prime[++m]=i,phi[i]=i-1;
for(int j=1;j<=m;++j){
if(prime[j]>v[i]||prime[j]>n/i) break;
v[i*prime[j]]=prime[j],
phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-1:prime[j]);
}
}
[POJ3090]Visible Lattice Points
When the nail coordinates \ ((x, y) \ ) if and only if \ (1 \ le x, y \ le N, x \ ne y and gcd (x, y) = 1 \) when
I.e., the answer is \ (3 + 2 * \ sum \ limits_ {i = 2} ^ N \ varphi (i) \)
This problem has a dimension liter version that is N N N Figure proved by personal Mobius inversion? ? ? ?
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1500,M=150+5,inf=0x3f3f3f3f,P=19650827;
int n,mx=1005,sum[N];
template <class t>void rd(t &x){
x=0;int w=0;char ch=0;
while(!isdigit(ch)) w|=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=w?-x:x;
}
int v[N],prime[N],cntp,phi[N];
void euler(){
memset(v,0,sizeof(v)),cntp=0;
for(int i=2;i<=mx;++i){
if(!v[i]) v[i]=i,prime[++cntp]=i,phi[i]=i-1;
for(int j=1;j<=cntp;++j){
if(prime[j]>v[i]||prime[j]>mx/i) break;
v[i*prime[j]]=prime[j],
phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-1:prime[j]);
}
}
}
int main(){
freopen("in2.txt","r",stdin);
//freopen("xor.out","w",stdout);
euler();sum[1]=0;
for(int i=2;i<=mx;++i) sum[i]=sum[i-1]+phi[i];
int T;rd(T);
for(int i=1;i<=T;++i) rd(n),printf("%d %d %d\n",i,n,3+(sum[n]<<1));
return 0;
}