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. Linq join right join left join

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...

  2. spring与spring-data-redis整合redis

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. CodeCombat最后一题GridMancer

    http://codecombat.com/play/level/gridmancer 刚开始没看懂,题目,后来才慢慢看懂的, 题目要求,用最少的矩形框填充空白的地方 var grid = this. ...

  4. zedgraph多个graphpane的处理

    这个问题需要研究,需要使用  zedgraph.masterpane.panelist 其他人做的效果--先预留一个官网的链接http://zedgraph.dariowiz.com/index113 ...

  5. java中的抽象类和抽象方法

    知识点:java中的抽象类和抽象方法 关键字abstract意为抽象的,可以用来修饰类和方法,分别称作抽象类和抽象方法 抽象类一般在多态的场景中使用 一:抽象类(abstract class) 在类的 ...

  6. ActiveMQ 负载均衡与高可用(转载)

    一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现 2.activemq的 ...

  7. ACMG遗传变异分类标准与指南

    2015年,美国权威机构——美国医学遗传学与基因组学学会(ACMG)编写和发布了<ACMG遗传变异分类标准与指南>.为帮助我国医疗工作者和遗传咨询从业者更好地理解ACMG遗传变异分类标准. ...

  8. js 捕捉滚轮的滚动

    滚动方向区分为正负: <!DOCTYPE html> <html> <head lang="en"> <meta charset=&quo ...

  9. [STL][C++]VECTOR

    参考:http://blog.csdn.net/hancunai0017/article/details/7032383 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个 ...

  10. 深入理解Hadoop之HDFS架构

    Hadoop分布式文件系统(HDFS)是一种分布式文件系统.它与现有的分布式文件系统有许多相似之处.但是,与其他分布式文件系统的差异是值得我们注意的: HDFS具有高度容错能力,旨在部署在低成本硬件上 ...