2190: [SDOI2008]仪仗队
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2648 Solved: 1682
[ Submit][ Status][ Discuss]
Description
作为体育委员,C君负责这次运动会仪仗队的训练。仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图)。 现在,C君希望你告诉他队伍整齐时能看到的学生人数。
Input
共一个数N。
Output
共一个数,即C君应看到的学生人数。
Sample Input
4
Sample Output
9
HINT
【数据规模和约定】 对于 100% 的数据,1 ≤ N ≤ 40000
Source
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
const int maxn = 4E4 + 40;
typedef long long LL;
int n,tot,phi[maxn],pri[maxn];
bool not_pri[maxn];
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> n;
for (int i = 2; i < n; i++)
{
if (!not_pri[i]) pri[++tot] = i,phi[i] = i - 1;
for (int j = 1; j <= tot; j++)
{
int Nex = i*pri[j];
if (Nex >= n) break;
not_pri[Nex] = 1;
if (i % pri[j] == 0) {phi[Nex] = phi[i]*pri[j]; break;}
else phi[Nex] = phi[i]*(pri[j]-1);
}
}
LL Ans = 0;
for (int i = 2; i < n; i++) Ans += 2LL*phi[i];
cout << Ans + 3LL;
return 0;
}