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. 用法总结:NSArray,NSSet,NSDictionary

    用法总结:NSArray,NSSet,NSDictionary Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序 ...

  2. vue-cli3 vue2 保留 webpack 支持 vite 成功实践

    大家好! 文本是为了提升开发效率及体验实践诞生的. 项目背景: 脚手架:vue-cli3,具体为 "@vue/cli-service": "^3.4.1" 库: ...

  3. Python3 shevel模块,更高级的json序列化数据类型模块(比pickle更高级)

    直接将数据类型以字典的格式 存到文件中去. 直接.get读取出来,

  4. SpringBoot 设置服务一启动就执行、初始化数据

    定义一个类实现ApplicationRunner接口,然后Override这个ApplicationRunner接口的run方法 @Component public class TaskRunner ...

  5. JAVA将文件转换成byte数组(byte[])

    /** * 将文件转换成byte数组 * @param filePath 文件File类 通过new File(文件路径) * @return byte数组 */ public static byte ...

  6. Android 运行C可执行程序

    p.p1 { margin: 0; font: 12px "Helvetica Neue"; color: rgba(69, 69, 69, 1) } p.p2 { margin: ...

  7. 【LeetCode】173. Binary Search Tree Iterator 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 保存全部节点 只保留左节点 日期 题目地址:http ...

  8. 【LeetCode】236. Lowest Common Ancestor of a Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. 1007 - Mathematically Hard

    1007 - Mathematically Hard    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 6 ...

  10. 小小明系列故事——游戏的烦恼(hdu 4517)

    小小明系列故事--游戏的烦恼 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)To ...