POJ 3090 Visible Lattice Points
来源:互联网 发布:陕西广电网络宽带电话 编辑:程序博客网 时间:2024/03/29 18:10
Description
A lattice point (x, y) in the first quadrant (x andy 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
4245231
Sample Output
1 2 52 4 133 5 214 231 32549
Source
【题目大意】:
从原点看第一象限里的所有点,能直接看到的点的数目是多少。(不包含原点)
【分析】:
与这道题很像,详情点击:http://blog.csdn.net/csyzcyj/article/details/17332211<BZOJ 2190 [SDOI2008]仪仗队 题解 >
【代码】:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<vector>#include<stack>#include<queue>using namespace std;#define MAXN 1001int C,ans[MAXN],p[MAXN];bool a[MAXN];void euler(){ int num=0; for(int i=2;i<=1000;i++) { if(!a[i]) { p[num++]=i; ans[i]=i-1; } for(int j=0;j<num&&p[j]*i<=1000;j++) { a[p[j]*i]=true; if(!(i%p[j])) { ans[i*p[j]]=ans[i]*p[j]; break; } else ans[i*p[j]]=ans[i]*(p[j]-1); } }}int main(){ //freopen("input.in","r",stdin); //freopen("output.out","w",stdout); scanf("%d",&C); euler(); for(int i=1;i<=C;i++) { int N; long long ans1=1; scanf("%d",&N); for(int j=2;j<=N;j++) ans1+=ans[j]; printf("%d %d %lld\n",i,N,2*ans1+1); } //system("pause"); return 0;}
- POJ 3090 Visible Lattice Points
- poj 3090 Visible Lattice Points
- poj 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- POJ - 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- poj Visible Lattice Points(3090)
- POJ 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- POJ-3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- poj 3090:Visible Lattice Points
- POJ 3090 Visible Lattice Points[]
- POJ 3090 Visible Lattice Points
- poj 3090 Visible Lattice Points
- POJ 1422 Air Raid
- iOS NSObject Class 详解
- NBNS简析
- Linux C中令人讨厌的段错误
- 中国最具声望16所大学,国际排名逐个数~
- POJ 3090 Visible Lattice Points
- linux HZ Tick Jiffies
- boot windows from linux
- Java 复用类
- POJ 2449 Remmarguts' Date 求K短路
- HDU 2037 今年暑假不AC
- iMessenger 2.0.14.0401版本预览和新功能简述
- ios项目中如何得到appdelegate对象
- tomcat学习笔记(一) 模拟一个简单的web server