码迷,mamicode.com
首页 > 其他好文 > 详细

【POJ3090】Visible Lattice Points

时间:2019-03-17 23:15:08      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:mes   max   nlogn   std   利用   can   ice   ase   操作   

题目大意:求 \[\sum\limits_{i=2}^n\phi(i)\]

题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果。

代码如下

#include <cstdio>
using namespace std;
const int maxn=3010;

int kase,n,phi[maxn];

int main(){
    int T;scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=2;i<=n;i++)phi[i]=i;
        for(int i=2;i<=n;i++)if(i==phi[i])
            for(int j=i;j<=n;j+=i)
                phi[j]=phi[j]/i*(i-1);
        long long ans=3;
        for(int i=2;i<=n;i++)ans+=(phi[i]<<1);
        printf("%d %d %lld\n",++kase,n,ans);
    }
    return 0;
}

【POJ3090】Visible Lattice Points

标签:mes   max   nlogn   std   利用   can   ice   ase   操作   

原文地址:https://www.cnblogs.com/wzj-xhjbk/p/10549349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!