2190: [SDOI2008] Honor guard Time limit:10 Sec Memory limit:259 MB
submit:2717 solved:1731
[Submit] [Status] [Discuss] Description
As a sports Commissioner, C June is responsible for the training of the honor guard. Guard of Honor is composed of students of N * N of the square, in order to ensure that the procession uniform, c June will follow the guard of Honor's left rear, according to the number of students in the line of sight to determine whether the team is neat (such as). Now, C-June wants you to tell him the number of students you can see when the team is neat.
Input
A total of a number n.
Output
A total of a number, that is, c June should see the number of students.
Sample Input4
Sample Output9
HINT
"Data size and conventions" for 100% of data, 1≤n≤40000
Source [Submit] [Status] [Discuss]
See later think is the sum of Phi, do not believe the data range will give so small (obviously is O (n) algorithm good, give a 40000 N is what mentality). Pay attention to the special sentence is good, it is said to need unsigned long long ...
1#include <bits/stdc++.h>2typedef unsignedLong Longull;3 Const intSiz =40005;4 intN, Pri[siz], isp[siz], tot; ull phi[siz];5Signed Main (void) {6scanf"%d", &n);7 for(inti =2; I <= N; ++i) {8 if(!isp[i]) pri[tot++] = i, phi[i] = i-1;9 for(intj =0; J < tot; ++j) {Ten if(i * pri[j] > N) Break; OneIsp[i * Pri[j]] =1; A ifIPri[j]) -Phi[i * Pri[j]] = phi[i] * (PRI[J)-1); - Else { thePhi[i * Pri[j]] = phi[i] * Pri[j]; Break; } - } - } -ull ans =2; + for(inti =2; I < n; ++i) -Ans + =Phi[i]; +(Ans <<=1) -=1; AStd::cout << (n >1? Ans:0) <<Std::endl; at}
@Author: Yousiki
Bzoj 2190: [SDOI2008] Honor Guard