算法复习——欧拉函数(poj3090)
题目:
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
题解:
欧拉函数模板题。
心得:
感觉欧拉函数稍微考得隐晦点的就是可视点问题了···嗯就这样
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;
const int N=;
int phi[N],sum[N],n;
void pre()
{
for(int i=;i<N;i++)
phi[i]=i;
for(int i=;i<N;i++)
if(phi[i]==i)
for(int j=i;j<N;j+=i)
phi[j]=phi[j]*(i-)/i;
for(int i=;i<N;i++)
sum[i]=phi[i]+sum[i-];
}
int main()
{
//freopen("a.in","r",stdin);
pre();
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int k;
scanf("%d",&k);
cout<<i<<" "<<k<<" "<<sum[k]*+<<endl;
}
return ;
}
算法复习——欧拉函数(poj3090)的更多相关文章
- Java实现 蓝桥杯 算法提高 欧拉函数(数学)
试题 算法提高 欧拉函数 问题描述 老师出了一道难题,小酱不会做,请你编个程序帮帮他,奖金一瓶酱油: 从1-n中有多少个数与n互质? |||||╭══╮ ┌═════┐ ╭╯让路║═║酱油专用车║ ╰ ...
- Java实现 蓝桥杯VIP 算法提高 欧拉函数
算法提高 欧拉函数 时间限制:1.0s 内存限制:512.0MB 说明 2016.4.5 已更新试题,请重新提交自己的程序. 问题描述 给定一个大于1,不超过2000000的正整数n,输出欧拉函数,p ...
- 欧拉函数,打表求欧拉函数poj3090
欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i ...
- 算法总结之欧拉函数&中国剩余定理
算法总结之欧拉函数&中国剩余定理 1.欧拉函数 概念:在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)( ...
- 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(SummerTrainingDay04-M 欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7450 Accepted: ...
- POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
随机推荐
- sql 函数 coalesce
SQL函数 coalesce 功能: 返回参数中第一个非null的值. 语法: coalesce(参数1,参数2,参数3,...);返回第一个非null的值. 一般情况下会与Nullif()函数一起使 ...
- tomcat 发布本地文件
应用场景,通过web,jsp访问本地mouse文件夹的静态文件 通过修改tomcat配置文件server.xml <!--在Host标签下加入Context标签,path指的是服务器url请求地 ...
- PBI DAX 中GroupBy
平时工作中经常会遇到Group By 的情形,用sql 写group by 很容易,在PBI中可以这样写: SUMMARIZE(表名,GroupBy Key ,"聚合列命名",DI ...
- 单调栈3_水到极致的题 HDOJ4252
A Famous City 题目大意 给出正视图 每一列为楼的高度 最少有几座楼 坑点 楼高度可以为0 代表没有楼 贡献了两发RE 原因 if(!s.empty()&&tem){s. ...
- 用例重试机制rerunfailures
安装 rerunfailures插件 pip install pytest-rerunfailures 使用: pytest --reruns 重试次数 如:pytest --reruns 2 重 ...
- CPP-基础:char、BYTE、byte
一,C++语言的内建类型中没“BYTE”这么个类型.BYTE是WINDOWS Platform SDK中windef.h里面定义的:typedef unsigned char BYTE; 二,char ...
- 对于WebAssembly编译出来的.wasm文件js如何调用
WebAssembly也叫浏览器字节码技术 这里就不过多的解释了网上很多介绍 主要是让大家知道在js里面如何调用执行它,我之前看WebAssemblyAPI时候反正是看得一脸懵逼 也是为了大家能更快的 ...
- vue表单验证:vee-validate中文提示
官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...
- sublime text 3143 最新激活方法
1)输入激活码 —– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60 ...
- PAT 乙级 1013
题目 题目地址:PAT 乙级 1013 思路 审题没把范围看清楚,没一次AC 题中m和n都表示第几个素数,范围是10000,所以查询的数组中需要的素数量至少10000,所以需要计算大概2~120000 ...