传送门

可以看出 (i, j) 能被看到,(i * k, j * k) 都会被挡住

暴力

所以 gcd(i, j) == 1 的话 ans ++

那么可以枚举一半(中轴对称),求解答案,只能拿30分

#include <cstdio>
#include <iostream> int n, ans; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline int gcd(int x, int y)
{
return !y ? x : gcd(y, x % y);
} int main()
{
int i, j;
n = read();
if(n == 1)
{
puts("0");
return 0;
}
for(i = 1; i < n; i++)
for(j = i + 1; j < n; j++)
if(gcd(i, j) == 1)
ans++;
printf("%d\n", ans * 2 + 3);
return 0;
}

 正解

可以看出,gcd(i,j) == 1 才能对答案有贡献,也就是互质,想到什么?phi 值

其实上面的暴力过程仔细来看也就是 phi 值 的求解

#include <cstdio>
#include <iostream> int n, ans;
int phi[500001]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline void euler_phi()
{
int i, j;
phi[1] = 1;
for(i = 2; i < n; i++)
if(!phi[i])
for(j = i; j < n; j += i)
{
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i - 1);
}
} int main()
{
int i, j;
n = read();
if(n == 1)
{
puts("0");
return 0;
}
euler_phi();
for(i = 1; i < n; i++) ans += phi[i];
printf("%d\n", ans * 2 + 1);
return 0;
}

  

最新文章

  1. C和指针 第七章 习题
  2. Mysql 与 Python socket
  3. 从Wep page到Application
  4. 替代jquery
  5. ADUM1201在隔离RS232中的应用 【瓦特芯收藏】
  6. c语言指针字符串与字符数组字符串的区别
  7. 28、Jquery 页面效果
  8. TextView实现多个TextView对象的走马灯效果
  9. Zookeeper Watcher 解析
  10. cors解决ajax请求跨域问题
  11. C语言第二次博客作业---分支结构 陈张鑫
  12. python全栈开发day59-Django基础
  13. spring+springMvc+struts的SSH框架整合
  14. numpy 介绍
  15. IOS返回go(-1)
  16. 介绍一个axios调试好用的工具:axios-mock-adapter
  17. JS 01 变量_数据类型_分支循环_数组
  18. Android通知栏沉浸式/透明化完整解决方案
  19. Unity如何内置Visual Studio
  20. 关于hibernate中的session与数据库连接关系以及getCurrentSession 与 openSession() 的区别

热门文章

  1. CF811C Vladik and Memorable Trip
  2. 微信小程序一些常见的坑
  3. mvc使用linq to sql进行sum统计遇到查询为null的问题
  4. LR接口测试---基于http协议之get/post
  5. android开发小内容
  6. CNN:测试一下YoloV3
  7. codeforces_305C_STLset
  8. Swift mutating Equatable Hashable 待研究
  9. WINVER WIN32 WINNT
  10. 生成count个[0-n)不重复的随机数