Poj 3090 Visible Lattice Points(欧拉函数)
来源:互联网 发布:学习c语言编程 编辑:程序博客网 时间:2024/05/18 02:29
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
4245231
Sample Output
1 2 52 4 133 5 214 231 32549
从点(0,0)到(x,y)不经过其他点 及x,y互素
问题 就变为求1到n内互素的数的对数 因为是对称的需要乘以2 另外还要加上(0,1)这个点
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 1010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int Read(){ char ch; int a = 0; while((ch = getchar()) == ' ' | ch == '\n'); a += ch - '0'; while((ch = getchar()) != ' ' && ch != '\n') { a *= 10; a += ch - '0'; } return a;}void Print(int a) //输出外挂{ if(a>9) Print(a/10); putchar(a%10+'0');}int phi[MAXN];void init(){ for(int i=1;i<MAXN;i++) phi[i]=i; for(int i=2;i<MAXN;i+=2) phi[i]/=2; for(int i=3;i<MAXN;i+=2) if(phi[i]==i) { for(int j=i;j<MAXN;j+=i) phi[j]=phi[j]/i*(i-1); } for(int i=2;i<MAXN;i++) phi[i]+=phi[i-1];}int main(){ //fread; int tc; scanf("%d",&tc); int cs=1; init(); while(tc--) { int n; scanf("%d",&n); printf("%d %d %d\n",cs++,n,phi[n]*2+1); } 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 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 2478 Farey Sequence & POJ 3090 Visible Lattice Points (欧拉函数)
- Visible Lattice Points - POJ 3090 欧拉公式
- Visible Lattice Points (欧拉函数)
- Visible Lattice Points 欧拉函数应用
- Visible Lattice Points(Poj3090)(欧拉函数运用)
- C#连接mysql数据库
- WIN7系统IIS配置与问题处理之二
- python 学习笔记之内置函数
- web service cxf demo
- 算法设计:排序
- Poj 3090 Visible Lattice Points(欧拉函数)
- 网络硬件三剑客:集线器、交换机与路由器
- Duilib技巧:背景图片平铺
- Python 学习笔记之列表(List)
- UVA 101 The Blocks Problem
- IntelliJ IDEA 配置MAVEN后从网上GIT项目仓库路径修改方法
- mac 下统计代码行数
- c++ vector的成员函数解析
- yii2操作数据库 mysql 读写分离 主从复制