http://poj.org/problem?id=3090

对于此题,观测点的数目,从小规模开始观察,可以得到每一个点,由一根无限长的绳子,绕着原点旋转,得到的第一个点。换另外一个思路,每一个观察到的点,都是子矩阵的一个边界点,也就是说枚举每一个子矩阵的点即可,而对于重合的点,则是已经出现的点,也就是可以约分的点,斜率可以看出。那么也就是欧拉函数,通过线性筛欧拉函数,然后对于每一个询问,直接计算欧拉函数和即可。因为是对称的,所以只要求一半,后面再乘2+加上k=1的那一个就可以了

 1 #include<iostream>
2 #include<stdio.h>
3 #include<cstring>
4 #include<math.h>
5 #include<algorithm>
6 using namespace std;
7 typedef long long ll;
8 const ll N=1e3+520;
9 bool vis[N];
10 ll phi[N],p[N],cnt;
11 ll n,ans,t;
12 void euler()
13 {
14 phi[1]=1;
15 for(int i=2;i<=N;i++)
16 {
17 if(!vis[i]) p[cnt++]=i,phi[i]=i-1;
18 for(int j=0;p[j]<=N/i;j++)
19 {
20 vis[p[j]*i]=1;
21 if(i%p[j]==0){phi[i*p[j]]=phi[i]*p[j];break;}
22 phi[i*p[j]]=phi[i]*(p[j]-1);
23 }
24 }
25 }
26 int main()
27 {
28 euler();
29 scanf("%lld",&t);
30 for(int i=1;i<=t;i++)
31 {
32 scanf("%lld",&n);
33 ans=0;
34 for(int j=1;j<=n;j++) ans+=phi[j];
35 printf("%d %lld %lld\n",i,n,ans*2+1);
36 }
37 return 0;
38 }

POJ3090Visible Lattice Points的更多相关文章

  1. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

  2. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  3. poj 3060 Visible Lattice Points

    http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  4. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

  5. POJ3090_Visible Lattice Points【欧拉函数】

    Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5653 Accepted: 333 ...

  6. P8 Visible Lattice Points

    P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x ...

  7. 【POJ】3090 Visible Lattice Points(欧拉函数)

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: ...

  8. POJ3090 Visible Lattice Points

    /* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...

  9. Visible Lattice Points (莫比乌斯反演)

    Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...

随机推荐

  1. 什么是SEO配置

    SEO是什么 搜索引擎优化,又称为SEO,即Search Engine Optimization,它是一种通过分析搜索引擎的排名规律,了解各种搜索引擎怎样进行搜索.怎样抓取互联网页面.怎样确定特定关键 ...

  2. PowerShell配置文件后门

      PowerShell 配置文件是在 PowerShell 启动时运行的脚本.   在某些情况下,攻击者可以通过滥用PowerShell配置文件来获得持久性和提升特权.修改这些配置文件,以包括任意命 ...

  3. SpringBoot整合Elasticsearch启动报错处理 nested exception is java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]

    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean wit ...

  4. IDEA报错 Unable to open debugger port (127.0.0.1:63342): java.net.BindException "Address already in use

    Unable to open debugger port (127.0.0.1:63342): java.net.BindException  "Address already in use ...

  5. ubuntu用户、用户组设置命令总结

    1.ubuntu创建新用户: sudo adduser username(新建一个用户username) 2.设置用户 username 的密码(设置用户username密码) sudo passwd ...

  6. ubuntu(Linux) c++ 获取本机IPv4和ipv6、查询本机IPv4,IPv6

    1.关于 演示环境: Linux xxxxxxx 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x ...

  7. 【LeetCode】83. Remove Duplicates from Sorted List 解题报告(C++&Java&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断相邻节点是否相等 使用set 使用列表 递归 日 ...

  8. 【LeetCode】808. Soup Servings 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/soup-serv ...

  9. 【LeetCode】888. Fair Candy Swap 公平的糖果棒交换(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人公众号: 每日算法题 本文关键词:力扣,LeetCode,算法题,算法,Python 目录 题目描述 题目大意 解题方法 代码 刷题心得 关于作 ...

  10. 初识TMMi——测试成熟度模型集成

    利用零碎的时间,粗略了解了一下TMMi V1.2,整理一下学习笔记跟大家分享一下. 本文分为四个部分,分别为TMMi概述.TMMi结构.成熟度级别和过程域.TMMi实施周期,希望能够帮助大家更好的理解 ...