可见的点
题目链接: https://www.acwing.com/problem/content/203/
思路:分析题目可知,除了(1,0),(0,1),(1,1)这三个点外,点(x,y)能被看到,
当且仅当x与y互质,由欧拉函数即可快速求出互质的点,除那三个点外,能被看到
的点关于直线y=x对称,所以只要求一边即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<cmath> #include<vector> using namespace std; int a[2000],sum[2000]; void fun() { for ( int i=2; i<=1000; i++) a[i]=i; for ( int i=2; i<=1000; i++) { if (a[i]==i) { for ( int j=i; j<=1000; j=j+i) a[j]=a[j]/i*(i-1); } } for ( int i=2; i<=1000; i++) sum[i]=sum[i-1]+a[i]; return ; } int main() { fun(); int n,t,u=0; scanf ( "%d" ,&t); while (t--) { scanf ( "%d" ,&n); printf ( "%d %d %d\n" ,++u,n,2*sum[n]+3); } return 0; } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步