Poj(2407),Greater New York Regional 2015 (D)
题目链接:http://poj.org/problem?id=2407
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13599 | Accepted: 6772 |
Description
Input
Output
Sample Input
7
12
0
Sample Output
6
4
Source
欧拉函数相当于一个筛选,找到一个素因数后,就将该素因子全部约掉。
#include <stdio.h> int Euler(int n)
{
int ans = n;
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
n/=i;
ans = ans - ans/i; while(n%i==)
{
n/=i;
} }
}
if(n>) ans = ans - ans/n;
return ans;
} int main()
{
int n;
while(scanf("%d",&n),n)
{
printf("%d\n",Euler(n));
}
return ;
}
#include <stdio.h> int Euler(int n)
{
int res = n;
for(int i=; i*i<=n; i++)
{
if(n%i==)
{
n=n/i;
res = res - res/i;
while(n%i==)
n/=i;
}
}
if(n>) res = res - res/n;
return res;
} int main()
{
int cases;
scanf("%d",&cases); int ans[];
ans[] = ;
for(int i=; i<=; i++)
{
ans[i]=ans[i-]+Euler(i);
}
while(cases--)
{
int t,k;
scanf("%d%d",&t,&k);
printf("%d %d\n",t,ans[k]);
}
return ;
}
Poj(2407),Greater New York Regional 2015 (D)的更多相关文章
- 【2011 Greater New York Regional 】Problem I :The Golden Ceiling
一道比较简单但是繁琐的三维计算几何,找错误找的我好心酸,没想到就把一个变量给写错了 = =: 题目的意思是求平面切长方体的截面面积+正方体顶部所遮盖的面积: 找出所有的切点,然后二维凸包一下直接算面积 ...
- 【2011 Greater New York Regional 】Problem G: Rancher's Gift
计算几何的题目,很简单: 自己随手敲了个,纪念下! #include<cstdio> #include<cmath> using namespace std; struct p ...
- 【2011 Greater New York Regional 】Problem H: Maximum in the Cycle of 1
也是一个数学题: 主要用到的是排列组合的知识,推推公式就行了,挺简单的: 唯一要注意的是A(0,0)=1: 在这个上面WA了几次,= = 代码: #include<stdio.h> #de ...
- 【2011 Greater New York Regional 】Problem B The Rascal Triangle
一个简单的规律题,每一列都是一个等差数列: 代码: #include<cstdio> #define ll long long using namespace std; int main( ...
- 75-ADMI,Average Directional Movement Index,平均方向性运动指标.(2015.7.1)
ADMI,Average Directional Movement Index 平均方向性运动指标 Directional Movement Index,平均方向性运动指标.(2015.7.1)&qu ...
- POJ 2407 (欧拉函数)
题目链接: http://poj.org/problem?id=2407 题目大意:求小于n且与n互质的正整数个数. 解题思路: 欧拉函数=小于n且与n互质的正整数个数. 公式=n*(1-1/P1)* ...
- Poj(2784),二进制枚举最小生成树
题目链接:http://poj.org/problem?id=2784 Buy or Build Time Limit: 2000MS Memory Limit: 65536K Total Sub ...
- POJ 2407 Relatives(欧拉函数)
http://poj.org/problem?id=2407 题意: 给出一个n,求小于等于的n的数中与n互质的数有几个. 思路: 欧拉函数的作用就是用来求这个的. #include<iostr ...
- poj 2407 欧拉函数裸题
http://poj.org/problem?id=2407 题意:多组数据,每次输入一个数 ,求这个数的欧拉函数 int euler_phi(int n){//单个欧拉函数 int m=(int)s ...
随机推荐
- 如何准确进行T+0操作
如何准确进行T+0操作 http://tangulunjin.com.cn/t0.html 常用的几种T+0模式 1.受外盘或者个股利好高开,高开一般在10点之前会有个回抽昨日收盘价的下跌波.特别是弱 ...
- __int64和long long输入输出
__int64 num; scanf("%I64d", &num); printf("%I64d\n", num); long long num; sc ...
- Excel操作增强包
一.前期准备1) pywin32安装包(根据系统要求选择32位装包还是64位安装包)2) xlwings安装包二.安装过程1) pywin32安装包为exe文件,直接进行安装即可2) xlwi ...
- [原创]java WEB学习笔记56:Struts2学习之路---Struts 版本的 登录 demo
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Web Project配置Hirbernate
1:首先找到hibernate-release-4.1.9.Final.zip\hibernate-release-4.1.9.Final\lib\required ,把required里的所有jar ...
- HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)
Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself ...
- dataset 使用
下面有例子说明: 首先我们需要打开一个联结: string MyConnString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/ ...
- ppaer 67 : matlab 函数errorbar
MATLAB ERRORBAR 这个函数的意思是:ERRORBAR(X,Y,L,U),X是自变量,Y是因变量,L是Y的变动下限,U是Y的变动上限 errorbar(X,Y,E) X是自变量,Y是因变 ...
- paper 13:计算机视觉研究群体及专家主页汇总
做机器视觉和图像处理方面的研究工作,最重要的两个问题:其一是要把握住国际上最前沿的内容:其二是所作工作要具备很高的实用背景.解决第一个问题 的办法就是找出这个方向公认最高成就的几个超级专家(看看他们都 ...
- BETWEEN and
select * from ( select *,ROW_NUMBER() over (ORDER BY AddTime desc) RowNumber from Product where ID n ...