102. Coprimes

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime if (and only if) their greatest common divisor is 1. (i.e. A and B are coprime iff gcd(A,B) = 1).

Input

Input file contains integer N.

Output

Write answer in output file.

Sample Input

9

Sample Output

6

注意欧拉函数只需要统计质因子
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=100;
int n;
int prim[maxn],len;
void divide(){
len=0;
int tn=n;
int r=sqrt(n+0.5)+1;
for(int i=2;i<r;i++){
if(tn%i==0){
prim[len++]=i;
while(tn%i==0)tn/=i;
}
}
if(tn!=1)prim[len++]=tn;
}
int phi(){
int ans=n;
for(int i=0;i<len;i++){
ans/=prim[i];
ans*=prim[i]-1;
}
return ans;
}
int main(){
while(scanf("%d",&n)==1){
divide();
int amount=phi();
printf("%d\n",amount);
}
return 0;
}

  

快速切题 sgu102.Coprimes 欧拉函数 模板程度 难度:0的更多相关文章

  1. UVA 10820 欧拉函数模板题

    这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...

  2. POJ 2407:Relatives(欧拉函数模板)

    Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accept ...

  3. hdu3501Calculation 2——欧拉函数模板

    题目: Problem Description Given a positive integer N, your task is to calculate the sum of the positiv ...

  4. poj2407(欧拉函数模板)

    sqrt(n)复杂度 欧拉函数模板 #include <iostream> #include <cstdio> #include <queue> #include ...

  5. poj3696 快速幂的优化+欧拉函数+gcd的优化+互质

    这题满满的黑科技orz 题意:给出L,要求求出最小的全部由8组成的数(eg: 8,88,888,8888,88888,.......),且这个数是L的倍数 sol:全部由8组成的数可以这样表示:((1 ...

  6. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  7. P2158 [SDOI2008] 仪仗队(欧拉函数模板)

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...

  8. SPOJ 5152 Brute-force Algorithm EXTREME && HDU 3221 Brute-force Algorithm 快速幂,快速求斐波那契数列,欧拉函数,同余 难度:1

    5152. Brute-force Algorithm EXTREME Problem code: BFALG Please click here to download a PDF version ...

  9. hdu1286 找新朋友 欧拉函数模板

    首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...

随机推荐

  1. bzoj 3600 没有人的算术 - 替罪羊树 - 线段树

    题目都是图片,就不给了,就给链接好了 由于bzoj比较慢,就先给[vjudge传送门] 有兴趣的可以去逛bzoj[bzoj传送门] 题目大意 有n个数a[1],a[2],...,a[n],它们开始都是 ...

  2. 小测(noip2005的两道题) 2017.3.3

    过河 题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把 ...

  3. HDU3652 B-number(数位DP)题解

    思路: 这里的状态分为3种,无13和末尾的1,无13且末尾为1,有13,然后DFS 等我搞清楚数位DP就来更新Orz 代码: #include<iostream> #include< ...

  4. poj 2449 Remmarguts' Date 求第k短路 Astar算法

    =.=好菜 #include <iostream> #include <cstdio> #include <string.h> #include <cstri ...

  5. dp暑假专题 训练记录

    A 回文串的最小划分 题意:给出长度不超过1000的字符串,把它分割成若干个回文字串,求能分成的最少字串数. #include <iostream> #include <cstdio ...

  6. 【jdk源码分析】java.lang.Appendable

    1.概述 public interface Appendable 能够被添加 char 序列和值的对象.如果某个类的实例打算接收取自 Formatter 的格式化输出,那么该类必须实现 Appenda ...

  7. The way to Go(7): 变量

    参考: Github: Go Github: The way to Go 变量 一般格式:var identifier type. Go在声明变量时将变量的类型放在变量的名称之后: 避免像 C 语言中 ...

  8. C++ 实验2:函数重载、函数模板、简单类的定义和实现

    1.函数重载编程 编写重载函数add(),实现对int型,double型,Complex型数据的加法.在main()函数中定义不同类型数据,调用测试. #include <iostream> ...

  9. Mui --- 弹出菜单

    mui框架内置了弹出菜单插件,弹出菜单显示内容不限,但必须包裹在一个含.mui-popover类的div中,如下即为一个弹出菜单内容: <div id="popover" c ...

  10. BZOJ 2669 【CQOI2012】 局部极小值

    题目链接:局部极小值 这是一道\(dp\)好题. 由于需要保证某些位置比周围都要小,那么我们可以从小到大把每个数依次填入,保证每个局部极小值填入之前周围都不能填,就只需要在加入的时候计数了. 由于局部 ...