\(\Large\textbf{Description:} \large{输入n,求有多少个二元组(x,y)满足:1\leqslant x,y\leqslant n,且x和y互素。}\)

\(\Large\textbf{Solution:} \large{不难发现除了(1,1)外,其他二元组的x,y都不相等。设满足x < y的二元组有g(n)个,那么答案为2\times g(n) + 1。}\)

\(\large{其中g(n)=\sum_{i=2}^n\Phi(i)}。\)

\(\Large\textbf{Code:}\)

#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long
#define gc() getchar()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 5e4 + 5;
int n, cnt, prime[N], phi[N];
LL sum[N];
bool vis[N]; inline int read() {
char ch = gc();
int ans = 0;
while (ch > '9' || ch < '0') ch = gc();
while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + ch - '0', ch = gc();
return ans;
} inline void euler() {
phi[1] = 1;
rep(i, 2, N) {
if (!vis[i]) prime[++cnt] = i, phi[i] = i - 1;
for (int j = 1; j <= cnt && i * prime[j] <= N; ++j) {
vis[prime[j] * i] = true;
if (i % prime[j] == 0) {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
} int main() {
euler();
rep(i, 1, N) sum[i] = sum[i - 1] + phi[i];
n = read();
while (n) {
printf("%lld\n", 2 * sum[n] - 1);
n = read();
}
return 0;
}

\(\large\color{pink}{by\quad Miraclys}\)

最新文章

  1. 适配iOS10 的相关权限设置
  2. SQL SERVER 内存分配及常见内存问题 DMV查询
  3. C++程序设计(一)
  4. shell判断一个变量是否为空
  5. Java泛型:泛型类、泛型接口和泛型方法
  6. @ContextConfiguration注解说明
  7. Sending e-mail with Spring MVC---reference
  8. 【USACO 3.2.5】魔板
  9. hadoop1.2.1+hbase0.90.4+nutch2.2.1+elasticsearch0.90.5配置(伪分布式)
  10. How many integers can you find(容斥+dfs容斥)
  11. C++Primer学习——类
  12. NIO之FileChannel类的理解和使用
  13. Activity简说
  14. get() got an unexpected keyword argument
  15. Mysql 函数使用记录(一)——DATEDIFF、CONCAT
  16. HTML的实际演练1
  17. freemarker时间转换
  18. USACO 4.3 Street Race
  19. DBA_实践指南系列5_Oracle Erp R12日常运维和管理(案例)
  20. python itertools模块练习

热门文章

  1. 利用DFS算出有多少个连通图
  2. swiper选项卡还可以左右滑动,最后一个直接跳转链接
  3. centos将uwsgi添加为系统服务
  4. 吴裕雄--天生自然ORACLE数据库学习笔记:用户管理与权限分配
  5. C 语言入门---第十一章---C语言重要知识点补充
  6. java.lang.ClassCastException: android.app.Application cannot be cast to
  7. UCOS-III API函数
  8. Linux centos7 LAMP架构介绍、 MySQL、MariaDB介绍、MySQL安装
  9. 使用mybase、Typora搭配坚果云实现个人云笔记
  10. Nginx多站点虚拟主机实现单独启动停止php-fpm、单独控制权限设置