博客
关于我
P2158 [SDOI2008]仪仗队
阅读量:798 次
发布时间:2023-02-26

本文共 1299 字,大约阅读时间需要 4 分钟。

P2158 [SDOI2008] 仪仗队

图是关于y=x对称的,横纵坐标一定是互质的,否则在之前就被扫过了,所以可以用欧拉函数再乘以2就完了。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 2147483647#define For(i, a, b) for (register int i = a; i <= b; i++)#define p(a) putchar(a)#define g() getchar()// by war// 2017.11.3using namespace std;int n;int ans;int prime[40010];bool vis[40010];int cnt, tot;int pr[40010];void in(int &x) { int y = 1; char c = g(); x = 0; while (c < '0' || c > '9') { if (c == '-') y = -1; c = g(); } while (c >= '0' && c <= '9') x = (x < 1) ? (x < 3 ? x + 2 : x + c - '0') : x * 10 + c - '0'; x *= y;}void o(int x) { if (x < 0) { p('-'); x = -x; } if (x > 9) o(x / 10); p(x % 10 + '0');}void Euler() { For(i, 2, n) { if (!vis[i]) prime[++cnt] = i; for (register int j = 1; j <= cnt && i * prime[j] <= n; j++) { vis[i * prime[j]] = true; if (i % prime[j] == 0) break; } }}int Eulerfunction(int x) { tot = 0; int c = x; For(i, 1, cnt) { if (prime[i] > x) break; if (x % prime[i] == 0) pr[++tot] = prime[i]; } For(i, 1, tot) c -= c / pr[i]; return c;}int main() { in(n); n--; Euler(); For(i, 1, n) ans += Eulerfunction(i); o(ans * 2 + 1); return 0;}

转载于: https://www.cnblogs.com/war1111/p/7779707.html

你可能感兴趣的文章
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
Orleans框架------基于Actor模型生成分布式Id
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>
ORM sqlachemy学习
查看>>
Ormlite数据库
查看>>
orm总结
查看>>
os.environ 没有设置环境变量
查看>>
os.path.join、dirname、splitext、split、makedirs、getcwd、listdir、sep等的用法
查看>>
os.removexattr 的 Python 文档——‘*‘(星号)参数是什么意思?
查看>>
os.system 在 Python 中不起作用
查看>>
OS2ATC2017:阿里研究员林昊畅谈操作系统创新与挑战
查看>>
OSCACHE介绍
查看>>
SQL--合计函数(Aggregate functions):avg,count,first,last,max,min,sum
查看>>
OSChina 周五乱弹 ——吹牛扯淡的耽误你们学习进步了
查看>>
SQL--mysql索引
查看>>
OSChina 周四乱弹 ——程序员为啥要买苹果手机啊?
查看>>
OSChina 周日乱弹 —— 2014 年各种奇葩评论集合
查看>>
OSChina 技术周刊第十期,每周技术抢先看!
查看>>