zoj 2777 Visible Lattice Points(欧拉函数,基础)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; int ans[];
int phi[],prime[],N=;
bool is_prime[]; void get_phi()
{
int i, j, k;
k = ;
//有些题目1的欧拉函数是1,请注意
//phi[1]=1;
for(i = ; i < N; i++)
{
if(is_prime[i] == false)
{
prime[k++] = i;
phi[i] = i-;
}
for(j = ; j<k && i*prime[j]<N; j++)
{
is_prime[ i*prime[j] ] = true;
if(i%prime[j] == )
{
phi[ i*prime[j] ] = phi[i] * prime[j];
break;
}
else
{
phi[ i*prime[j] ] = phi[i] * (prime[j]-);
}
}
}
} int main()
{
int i,t,n;
get_phi();
ans[]=;
for(i=;i<;i++)
{
ans[i]=ans[i-]+phi[i]*;
}
scanf("%d",&t); for(i=;i<=t;i++)
{
scanf("%d",&n);
printf("%d %d %d\n",i,n,ans[n]);
}
return ;
}
zoj 2777 Visible Lattice Points(欧拉函数,基础)的更多相关文章
- POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...
- POJ 3090 Visible Lattice Points 欧拉函数
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
- POJ3090 Visible Lattice Points 欧拉筛
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- POJ_3090 Visible Lattice Points 【欧拉函数 + 递推】
一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
- POJ 3090 Visible Lattice Points 【欧拉函数】
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...
随机推荐
- functional javascript
(转载请注明出处!) 今早带我的master跟我分享了他最近看<functional javascript>一书的感悟,瞬间觉得写1w行代码都不如看本好书来的好啊! 于是在下午的写的项目中 ...
- UIScrollView,UIPageControl
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIScrollViewDelegate&g ...
- unity打包android游戏部分问题总结
一:虚拟导航栏挡到游戏按钮: 解决方案如下: 1.获取焦点的时候隐藏 虚拟导航条 Navigation bar 隐藏导航条 2.出现导航条的时候,改变游戏界面大小 Unity tidbits: cha ...
- windows phone 手机截图
无聊在商城找了一款小游戏玩,看到一个截屏功能,就google了一下具体实现,还是比较简单的,主要是靠WriteableBitmap(提供一个可写入并可更新的 BitmapSource)类实现.看一下m ...
- 《gpg文件加密的使用》RHEL6
甲端: 首先是要生成一对密钥: 提示是否要生成2048个字节的密钥对: 下面都是生成密钥对时的步骤: 按“o”键开始生成密钥对: 提示要我给密钥对加个密码: 输入2次 之后密钥对的字符需要我按键盘 ...
- Winform 拦截最小化、最大化、关闭事件【整理】
const int WM_SYSCOMMAND = 0x112; //窗体关闭消息 const int SC_CLOSE = 0xf060; //窗体最小化消息 const int SC_MINIMI ...
- c#获取今天星期几
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)
- Redis源码研究--跳表
-------------6月29日-------------------- 简单看了下跳表这一数据结构,理解起来很真实,效率可以和红黑树相比.我就喜欢这样的. typedef struct zski ...
- CentOS安装 pure-ftpd
yum -y install pam-devel cd /usr/local .tar.gz cd pure-ftpd- ./configure --prefix=/usr/local/pure-ft ...
- Spiral Matrix
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...