洛谷P2158仪仗队(数学,观察找规律,欧拉函数)

题目链接:https://www.luogu.org/problemnew/show/P2158

 

读完题被吓到了,这是什么东西。

总之,需要观察+找规律啊!观察可以发现,从第三行开始,第i行中当前直角三角形范围内能观察到的点数等于(i-1)的欧拉函数值

 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 #include <cstdio>
 5 #include <cstring>
 6 using namespace std;
 7 typedef long long ll;
 8 typedef unsigned long long ull;
 9 const int maxn=1e3+5;
10 const int inf=1e9;
11 int vis[maxn];
12 int n,ans;
13 
14 int Euler(int n)
15 {
16     if(n==1) return 1;
17     int ans=n;
18 
19     for(int i=2;i*i<=n;++i)
20     {
21         if(n%i==0)
22         {
23             while(n%i==0) n/=i;
24             ans=ans/i*(i-1);
25         }
26     }
27     if(n!=1) ans=ans/n*(n-1);
28 
29     return ans;
30 }
31 
32 int main()
33 {
34     ios::sync_with_stdio(false); cin.tie(0);
35 
36     cin>>n;
37 
38     if(n==1)
39     {
40         putchar('\0');
41         return 0;
42     }
43     for(int i=3;i<=n;i++) ans+=Euler(i-1);
44 
45     cout<<ans*2+3<<endl;
46     
47     //或者下面写法
48     //for(int i=1;i<=n-1;i++) ans+=Euler(i);
49     //cout<<ans*2+1<<endl;
50 
51     return 0;
52 }

 

完。

转载于:https://www.cnblogs.com/redblackk/p/9787221.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值