Relatives
Description
Input
Output
Sample Input
7
12
0
Sample Output
6
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long LL ;
int euler(int n){ //返回euler(n)
int res=n,a=n;
for(int i=2;i*i<=a;i++){
if(a%i==0){
res=res/i*(i-1);//先进行除法是为了防止中间数据的溢出
while(a%i==0) a/=i;
}
}
if(a>1) res=res/a*(a-1);
return res;
} int main (){
int x;
while(~scanf("%d",&x)&&x){
printf("%d\n",euler(x));
}
return 0;
}
Relatives的更多相关文章
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- POJ 2407 Relatives(欧拉函数入门题)
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- Text Relatives II
[Text Relatives II] When your app determines that the user has requested the edit menu—which could b ...
- Text Relatives
[Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...
- God made relatives.Thank God we can choose our friends.
God made relatives.Thank God we can choose our friends. 神决定了谁是你的亲戚, 幸运的是在选择朋友方面他给了你留了余地
- POJ 2021 Relative Relatives
Relative Relatives Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3339 Accepted: 146 ...
- Relatives(容斥)
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15708 Accepted: 7966 Descri ...
- POJ 2407 Relatives 【欧拉函数】
裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i ...
随机推荐
- JavaScript中的eval()函数
和其他很多解释性语言一样,JavaScript同样可以解释运行由JavaScript源代码组成的字符串,并产生一个值.JavaScript通过全局函数eval()来完成这个工作. eval(“1+2” ...
- GIT(分布式版本控制系统)
Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.[1] Git的读音为/gɪt/. Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本 ...
- IEEE参考文献格式
IEEE参考文献格式 由于国外期刊参考文献与国内参考文献的格式有很大区别,其中最常用的参考文献为会议论文.书籍.期刊文献,所以特别在此记录说明,方便以后使用. 会议论文(Published Confe ...
- 使用HTML5+CSS3制作圆角内发光按钮----示例
<!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...
- HDU 3622 Bomb Game(二分+2SAT)
题意:有一个游戏,有n个回合,每回合可以在指定的2个区域之一放炸弹,炸弹范围是一个圈,要求每回合的炸弹范围没有重合.得分是炸弹半径最小的值.求可以得到的最大分数. 思路:二分+2SAT. 二分炸弹范围 ...
- Logistic回归小结
1.梯度上升优化 1). 伪代码: 所有回归系数初始化为1-------------------weights = ones((colNum,1)) 重复r次: 计算整个数据集的梯度gradient ...
- c# List 按类的指定字段排序
List<Report> list=Report.FindAllbyClassID(id); ) { list.Sort(delegate(Report x,Report y){ret ...
- 带优先级的队列 - PHP实现
很久以前写的一个功能,当时需要一个优先级的队列,特用新学的swoole写了一个简单的demo,仅满足当时的需求. 功能说明: 完全参考httpsqs增加优先级参数level 例: ...
- sublime 的使用
常见问题: ctrl+`快捷见弹不出console怎么办! 解决方法: 估计适合电脑其他软件的快捷键冲突了,在sublime里面重新设置下快捷键 点击菜单中Preferences下面的Key Bind ...
- Jquery 中的$(this) 和javascript中的this
this 是 JavaScript 中的关键字. $(this) 可以认为是用 jQuery 包装过 JavaScript 中的 this,包装后 $(this) 就会继承 jQuery 的方法. 本 ...