The Euler function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+….+ (b)
Input
There are several test cases. Each line has two integers a, b (2
Output
Output the result of (a)+ (a+1)+….+ (b)
Sample Input
3 100
Sample Output
3042
Source
2009 Multi-University Training Contest 1 - Host by TJU
题目大意
求a-b的phi[i]之和
没看到several cases WA了N多次QAQQQQQQ
const
maxn=10000000;
var
check:array[0..maxn]of boolean;
phi,prime:array[0..maxn]of longint;
n,i,j,a,b,len:longint;
ans:int64;
begin
n:=3000000;
len:=0;
for i:=2 to n do
begin
if check[i]=false
then begin inc(len); phi[i]:=i-1; prime[len]:=i; end;
for j:=1 to len do
begin
if prime[j]*i>n
then break;
check[i*prime[j]]:=true;
if i mod prime[j]=0
then begin phi[i*prime[j]]:=phi[i]*prime[j]; break; end
else phi[i*prime[j]]:=phi[i]*(prime[j]-1);
end;
end;
while not eof do
begin
readln(a,b);
ans:=0;
for i:=a to b do
inc(ans,phi[i]);
writeln(ans);
end;
end.