POJ3090
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7094 | Accepted: 4288 |
Description
A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (x, y) with 0 ≤ x, y ≤ 5 with lines from the origin to the visible points.
Write a program which, given a value for the size, N, computes the number of visible points (x, y) with 0 ≤ x, y ≤ N.
Input
The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.
Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.
Output
For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.
Sample Input
4
2
4
5
231
Sample Output
1 2 5
2 4 13
3 5 21
4 231 32549
Source
#include<cstdio>
using namespace std;
const int N=;
int T,n,tot,phi[N],prime[N/];
bool check[N];
void prepare(){
phi[]=;n=;
for(int i=;i<=n;i++){
if(!check[i]) prime[++tot]=i,phi[i]=i-;
for(int j=;j<=tot&&i*prime[j]<=n;j++){
check[i*prime[j]]=;
if(!(i%prime[j])){phi[i*prime[j]]=phi[i]*prime[j];break;}
else phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
int main(){
prepare();
scanf("%d",&T);
for(int i=;i<=T;i++){
scanf("%d",&n);
int ans=;
for(int j=;j<=n;j++) ans+=phi[j];
ans<<=;ans|=;
printf("%d %d %d\n",i,n,ans);
}
return ;
}
POJ3090的更多相关文章
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- POJ3090 巧用欧拉函数 phi(x)
POJ3090 给定一个坐标系范围 求不同的整数方向个数 分析: 除了三个特殊方向(y轴方向 x轴方向 (1,1)方向)其他方向的最小向量表示(x,y)必然互质 所以对欧拉函数前N项求和 乘2(关于( ...
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- 【POJ3090】Visible Lattice Points
题目大意:求 \[\sum\limits_{i=2}^n\phi(i)\] 题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果. 代码如下 #include <cstdio ...
- 欧拉函数,打表求欧拉函数poj3090
欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i ...
- POJ3090 Visible Lattice Points (数论:欧拉函数模板)
题目链接:传送门 思路: 所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1). #include <iostream> #include <cst ...
- POJ3090(SummerTrainingDay04-M 欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7450 Accepted: ...
- [POJ3090]Visible Lattice Points(欧拉函数)
答案为3+2*∑φ(i),(i=2 to n) Code #include <cstdio> int T,n,A[1010]; void Init(){ for(int i=2;i< ...
- POJ3090:Visible Lattice Points——题解
http://poj.org/problem?id=3090 题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点. 很容易想到,我们能看到的点,它的横纵坐标一定是互质 ...
随机推荐
- [Spring boot] A quick REST API Guide
Controller: Code below shows a basic Controller to handle GET, POST; DELETE, PUT requests. package h ...
- [Typescript] Make TypeScript Class Usage Safer with Strict Property Initialization
By setting the strictPropertyInitialization flag in the .tsconfig file, TypeScript will start throwi ...
- 服务端渲染 SSR
1.概述 SSR:网站内容由服务端渲染,然后返回客户端(查看网页源代码,所有内容都在源代码里面). 2.SSR优势 (1)SSR利于SEO. (2)SSR减少请求量和客户端渲染时间.
- 提高PAAS安全性的一点尝试
云服务已经成为现代人生活的一部分.手机中的照片会自己主动同步到云中:你的邮件内容保存在云中.办公软件执行在云中:你的健康数据会实时上传到云中.你每天的生活轨迹消耗的卡路里也会上传到云中:云服务也会逐渐 ...
- javascript 捕获异常方法
捕获异常的实例: var str="fasdfsadfsad$$异常信息$$你看不到我"; var arr=str.split("$$"); arr[1]; 通 ...
- 如何查看mysql数据库的引擎/MySQL数据库引擎详解
一般情况下,mysql会默认提供多种存储引擎,你可以通过下面的查看: 看你的mysql现在已提供什么存储引擎:mysql> show engines; 看你的mysql当前默认的存储引擎:mys ...
- 数据库面试题.net
1.ADO.net中常用的对象 connection, command, sqladapter, dataset, dataview. 2.net中读写数据库要用到哪些类 DataSet数据存储 Da ...
- Mac 常用命令介绍
1.查看所有shell cat /etc/shells 2.查看当前使用的shell类型 $ echo $SHELL 3.
- Atitit.嵌入式web 服务器 java android最佳实践
Atitit.嵌入式web 服务器 java android最佳实践 1. Android4.4.21 2. 自己的webserver1 3. CyberHTTP for Java cybergar ...
- Atitit.java jna 调用c c++ dll的原理与实践 总结 v2 q27
Atitit.java jna 调用c c++ dll的原理与实践 总结 v2 q27 1. Jna简单介绍1 2. Jna范例halo owrld1 3. Jna概念2 3.1. (1)需 ...