您的位置:首页 > 其它

[NOI2010]:能量采集

2017-12-13 21:46 295 查看
传送门

首先,80分暴力很明显,直接枚举然后算gcd就好了

然后其实100分也很简单(要不然怎么可能给80分暴力)

枚举gcd,然后算有多少个gcd(i,j)=d就好了,这里需要减去之前重复的,可以看我的代码。

代码:

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,m;
ll f
,ans;
int main(){
scanf("%d %d",&n,&m);
if(n>m)swap(n,m);
for(int i=n;i>=1;i--){
f[i]=(ll)(n/i)*(ll)(m/i);
for(int j=(i<<1);j<=n;j+=i)f[i]-=f[j];
ans+=(ll)((i<<1)-1)*f[i];
}
printf("%lld",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: