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

首先找出n的质因子,然后走一次o(n)找出所有不互质的数,减去即可,注意1与自身互质。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define maxn 10005 int n,len = ;
int ele[];
bool prime[maxn],vis[maxn]; void solve() {
for(int i = ; i <= n; i++) {
prime[i] = i % ;
} prime[] = ;
int ans = n;
for(int i = ; i < n; i++) {
if(prime[i]) {
if(n % i == ) {
ele[len++] = i;
}
for(int j = i; j * i <= n; j++) {
prime[j * i] = ;
} }
} vis[] = ;
int sum = ;
for(int i = ; i < len; i++) {
for(int j = ; j < n; j++) { if(j % ele[i] == ) vis[j] = ;
}
} for(int j = ; j < n; j++) if(vis[j]) sum++;
sum++;
if(prime[n]) printf("%d\n",n - );
else
printf("%d\n",ans - sum); }
int main()
{ scanf("%d",&n); if(n == ) printf("1\n");
else solve(); //cout << "Hello world!" << endl;
return ;
}

SGU 102的更多相关文章

  1. sgu 102 Coprimes

    太水了, 我都不忍心发题解, 但毕竟是sgu上一道题, 我试试能不能一直这么写下去,就是求phi,上代码 #include <cstdio> #include <cstring> ...

  2. sgu 102 Coprimes 解题报告及测试数据

    102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB 题解: 求一个1-10000之间的数 N 的互质 ...

  3. sgu 102模拟欧拉函数

    感觉自己弱爆了,做做SGU吧... #include<iostream> #include<cmath> //欧拉函数 using namespace std; int eul ...

  4. Coprimes - SGU 102(求互质数,水)

    题目大意:给你一个正整数N,求出来不超过N 的并且与N互质的正整数的个数. 就是一个大水题~~~ 代码: #include<stdio.h> #include<string.h> ...

  5. SGU刷题之路开启

    VJ小组:SGU---48h/题 每道做出的题目写成题解,将传送门更新在这里. SGU:101 - 200 SGU - 107 水题 解题报告 SGU - 105 找规律水题 解题报告 SGU - 1 ...

  6. (欧拉公式 很水) Coprimes -- sgu -- 1002

    链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/B Coprimes 时限:250MS     内存:4096KB     6 ...

  7. SGU 乱搞日志

    SGU 100 A+B :太神不会 SGU 101 Domino: 题目大意:有N张骨牌,两张骨牌有两面有0到6的数字,能相连当且仅当前后数字相同,问能否有将N张骨牌连接的方案?思路:裸的欧拉回路,注 ...

  8. 今日SGU 5.1

    SGU 100 题意: 普通的a+b #include<bits/stdc++.h> #define de(x) cout<<#x<<"="&l ...

  9. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

随机推荐

  1. 命令行工具cmder

    1.下载地址 http://bliker.github.io/cmder/ 分为两个版本:mini版和Full版 2.快捷命令配置: 比如,快速启动canssandra/redis数据库服务和查询工具 ...

  2. EMVTag系列17《9F66 终端交易属性》

    字节:1 8    1 – 支持非接触磁条 (MSD) 0– 不支持非接触磁条 (MSD) 7    1 – 支持非接触PBOC 0– 不支持非接触PBOC 6    1 – 支持非接触qPBOC 0 ...

  3. 【转载】alter table move 和 alter table shrink space的区别

    move 和shrink 的共同点1.收缩段2.消除部分行迁移3.消除空间碎片4.使数据更紧密 shrink 语法:  alter table TABLE_NAME shrink space [com ...

  4. Cygwin ssh服务配置 (SecureCRT连接Cygwin配置)

    1.运行ssh-host-config 这里需要注意的是标红部分,输入的用户名或密码要符合计算机的用户名或密码策略(尤其是公司有权限限制的电脑). $ ssh-host-config *** Quer ...

  5. arcgis中注记的高级处理

    在实际制图过程中,常遇到一个图层的多个要素展示,将标注转换为注记的之后,可以对注记进行移动调整位置等手动更改.这样为避免重复地移动注记位置.可以采用如下方案: 1.将图层标注转换为注记 2.将注记存储 ...

  6. android开发系列之MVP设计模式

    最近在开发一个android的项目中,发现了一个很实用的设计模式(MVP).大家可能一看到这个名字就有点蒙,MVP到底是什么鬼呢?它的好用到底体现在哪呢?别着急,下面就让我们一一分享出来. 说到MVP ...

  7. < java.util >-- Set接口

    Set接口中的方法和Collection中方法一致的.Set接口取出方式只有一种,迭代器. |--HashSet:底层数据结构是哈希表,线程是不同步的.无序,高效: HashSet集合保证元素唯一性: ...

  8. SqlServer正在执行的sql语句

    SELECT [Spid] = session_Id ,ecid ,[Database] = DB_NAME(sp.dbid) ,[User] = nt_username ,[Status] = er ...

  9. heap size eclipse 堆内存

    可以根据eclipse 或 myeclipse heapstats 使用情况调整堆内存大小,heap size 设置,-vmargs-Xms256-Xmx1024 ,其中Xms表示初始值,Xmx表示最 ...

  10. 关于arguments对象以及函数的柯里化;

    1.arguments对象 Arguments是个类似数组但不是数组的对象,说他类似数组是因为其具备数组相同的访问性质及方式,能够由arguments[n]来访问对应的单个参数的值,并拥有数组长度属性 ...