BZOJ-2190 [SDOI2008]仪仗队

数论。。。

答案就是前n-1个欧拉函数的总和再*2+1

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define clr(x, c) memset(x, c, sizeof(x))
#define maxn 45678
using namespace std;
inline int read()
{
	int x=0, f=1; char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
	return x*f;
}
int f[maxn];
int main()
{
	int n=read()-1, ans=0; 
	rep(i, 1, n) f[i]=i;
	rep(o, 2, n) if (f[o]==o) for(int i=o; i<=n; i+=o) f[i]=f[i]/o*(o-1);
	rep(i, 1, n) ans+=f[i]; 
	if (!n) printf("0\n"); else printf("%d\n", ans*2+1);
	return 0;
}

转载于:https://www.cnblogs.com/NanoApe/p/4479902.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值