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. kettle日志记录

    环境描述: 现在一个项目有很多个作业,需要知道每次跑批后哪些ktr跑成功,哪些失败了 问题解决: 下面是一个具体的操作流程 首先建立数据库表 CREATE TABLE test_1(id INT,NA ...

  2. VPN错误800、错误789

    VPN突然无法连接解决方法: 1. 单击“开始”,单击“运行”,键入“regedit”,然后单击“确定” 2. 找到下面的注册表子项,然后单击它:HKEY_LOCAL_MACHINE\System\C ...

  3. 删除undotbs后,数据库无法启动

    SQL> archive log list;Database log mode              No Archive ModeAutomatic archival            ...

  4. hdu 5104 Primes Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...

  5. TFS使用指南

    上一篇文章已经简略介绍过TFS的安装与管理,本篇文章主要描述一下我个人在工作过程中使用TFS的一些指南与建议.本章内容预览: 1.  项目计划与跟踪 经常有很多朋友在日常聊天中抱怨做计划很无畏,因为计 ...

  6. 如何破解UltraEdit

    在断网的前提下,软件->帮助->注册->激活->脱机激活—>用户和密码随便输入->还有两个空着,就是该用注册机激活了. 打开注册机->输入ULtredit的自 ...

  7. 56.ISE综合,在chipscope信号列表看不到

    代码写好后,进行逻辑综合,在chipscope上添加被触发的信号时,发现有些在信号列表里看不到,这是因为这些信号没有参与到逻辑电路设计中,产生不想关的电路,综合器会默认优化资源. 还有一种情况是,对于 ...

  8. C++设计模式——代理模式

    前言 青春总是那样,逝去了才开始回味:大学生活也是在不经意间就溜走了,现在上班的时候,偶尔还会怀念大学时,大家在一起玩游戏的时光.大学喜欢玩游戏,但是可悲的校园网,速度能把人逼疯了:还好,后来搞了一个 ...

  9. asdoc 档案

    1.asdoc air项目会出现无法找到NativeApplication等错误 解决办法:add args   -load-config ....../frameworks/air-config.x ...

  10. QTP与Selenium的比较

    1.用户仿真:Selenium在浏览器后台执行,它通过修改HTML的DOM(文档对象模型)来执行操作,实际上是通过javascript来控制的.执行时窗口可以最小化,可以在同一机器执行多个测试.QTP ...