POJ3090Visible Lattice Points
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的更多相关文章
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- poj 3060 Visible Lattice Points
http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Tota ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- POJ3090_Visible Lattice Points【欧拉函数】
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5653 Accepted: 333 ...
- P8 Visible Lattice Points
P8 Visible Lattice Points Time Limit:1000ms, Memory Limit:65536KB Description A lattice point (x ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- Visible Lattice Points (莫比乌斯反演)
Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...
随机推荐
- Samba 源码解析之SMBclient命令流
smbclient提供了类似FTP式的共享文件操作功能, 本篇从源码角度讲解smbclient的实现,smbclient命令的具体使用可通过help命令和互联网查到大量资料. 以下从源码角度分析一个s ...
- <转>企业应用架构 --- 分层
系统架构师-基础到企业应用架构-分层[上篇] 一.前言 大家好,接近一年的时间没有怎么书写博客了,一方面是工作上比较忙,同时生活上也步入正轨,事情比较繁多,目前总算是趋于稳定,可以有时间来完善以前没有 ...
- LuoguP7019 [NWRRC2017]Auxiliary Project 题解
Update \(\texttt{2021.6.24}\) 修改了一处格式上的错误和一处笔误. Content 已知用 LED 灯来显示 \(0\sim9\) 这十个数字分别需要 \(6,2,5,5, ...
- loger4j时间一长,就不向数据库里写日志啦,然而重新启动工程后就可以再次向数据库写日志,好奇怪
loger4j时间一长,就不向数据库里写日志啦,然而重新启动工程后就可以再次向数据库写日志,好奇怪
- Linux三剑客综合练习
1.找出/proc/meminfo文件中以s开头的行,至少用三种方式忽略大小写 [root@localhost ~]# grep -E '^[sS]' /proc/meminfo [root@loca ...
- JS判断是否为“YYYYMMDD”式的日期
function isDate8(sDate) { if (!/^[0-9]{8}$/.test(sDate)) { return false; } var year, month, day; yea ...
- CMake判断操作系统和编译器
判断操作系统 IF (CMAKE_SYSTEM_NAME MATCHES "Linux") ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Wind ...
- 【LeetCode】753. Cracking the Safe 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/cracking ...
- 【LeetCode】893. Groups of Special-Equivalent Strings 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- VMware15 虚拟机分别设置连接笔记本的WLAN和以太网双网络
VMware15 虚拟机分别设置连接笔记本的WLAN和以太网双网络 虚拟机:window 10 主机: window 10 VVmware有3种网络连接模式:桥接.NAT.主机模式,默认分别对应VMN ...