POJ 3090
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8397 | Accepted: 5144 |
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
[Submit] [Go Back] [Status] [Discuss]
刚开始脑子简单去暴力循环。。当然是T掉啦!
原来一直不明白欧拉函数,f(n)代表小于n的正整数中与n互质的数的数目。。就是这个题嘛。。记住了。
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<iostream>
#include <cmath>
#include<string>
#define ll long long
#define dscan(a) scanf("%d",&a)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
#define MAXL 1105
#define maxn 1000005
int f[MAXL];
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
return x*f;
}
int p[MAXL], pNum, phi[MAXL];
void ola()
{
int i, j;
for(i = ; i < MAXL; i++) {
if(!f[i]) { p[pNum++] = i; phi[i] = i-;}
for(j = ; j < pNum && p[j] * i < MAXL; j++ ) {
f[p[j]*i] = ;
if(i % p[j] == ){
phi[i*p[j]] = phi[i] * p[j];
break;
}
else phi[i*p[j]] = phi[i] *(p[j] - );
}
}
}
int main()
{
int n,c;
cin>>n;int hh=;
ola();
while(n--)
{
int c=read();
phi[]=;
cout<<hh++<<" "<<c<<" ";
ll ans=;
for(int i=;i<=c;++i) ans+=phi[i];
cout<<ans*+<<endl;
}
}
POJ 3090的更多相关文章
- POJ 3090 Visible Lattice Points 欧拉函数
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- 【POJ 3090】 Visible Lattice Points
[题目链接] http://poj.org/problem?id=3090 [算法] 通过观察发现,在这个平面直角坐标系中,除了(1,1),(1,0)和(0,1),所有可见点的横纵坐标互质 那么,问题 ...
- POJ 3090 Visible Lattice Points (ZOJ 2777)
http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- POJ 3090 (欧拉函数) Visible Lattice Points
题意: UVa 10820 这两个题是同一道题目,只是公式有点区别. 给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 对于点(x, y), 若g = gcd(x, y) ...
- poj 3090 Visible Lattice Points(离线打表)
这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规 ...
- POJ 3090 Visible Lattice Points 【欧拉函数】
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
随机推荐
- madplay移植
移植前需求准备: a. 源码包: 1. libid3tag-0.15.1b.tar.gz 2. libmad-0.15.1b.tar.gz 3. madplay-0.15.2b.tar.gz 4. z ...
- 三步搞定Vmware固定虚拟机的IP
1.修改vmware的虚拟网络编辑器 按照图中红色方框的方法设置,子网IP可以设置成自己想要的,点击NAT设置,记住网关IP. 2.进入centos虚拟机系统 编辑 vim /etc/sysconfi ...
- OpenFaceswap 入门教程(3): 软件参数篇!
OpenFaceswap 的使用可以说是非常简单,只要稍加点拨就可以学会,厉害一点的人根本不需要教程,直接自己点几下就知道了.看了前面安装篇和使用篇.我想大多数人应该会了. 当学会了使用之后,你可能对 ...
- 第7章 数据库访问与ORM 慕课网微信小程序开发学习笔记
第7章 数据库访问与ORM https://coding.imooc.com/learn/list/97.html 目录: 7-1 数据库操作三种方式之原生SQL 19:09 7-2 从一个错误了解E ...
- Redis之Hash类型操作
接口IRedisDaoHash: package com.net.test.redis.base.dao; import com.net.test.redis.base.entity.UserPsg; ...
- python3.7 json模块
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 json模块 ''' 要在不同的编程语言之间传递对象,就必须把对 ...
- C++多态实例
#include <iostream> #include <string> using namespace std; //class 实现 class Employee { s ...
- 容斥原理:HDU-4135Co-prime
容斥原理公式:这里就需要用到容斥原理了,公式就是:n/2+n/3+n/5-n/(2*3)-n/(2*5)-n/(3*5)+n/(2*3*5). 求的是多个重合区间的里面的数字个数. 解题心得: 1.一 ...
- [jzoj5233]概率博弈(树形DP)
Description 小A和小B在玩游戏.这个游戏是这样的: 有一棵
- Java并发——synchronized和ReentrantLock的联系与区别
0 前言 本文通过使用synchronized以及Lock分别完成"生产消费场景",再引出两种锁机制的关系和区别,以及一些关于锁的知识点. 本文原创,转载请注明出处:http:// ...