SGU 102
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的更多相关文章
- sgu 102 Coprimes
太水了, 我都不忍心发题解, 但毕竟是sgu上一道题, 我试试能不能一直这么写下去,就是求phi,上代码 #include <cstdio> #include <cstring> ...
- sgu 102 Coprimes 解题报告及测试数据
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB 题解: 求一个1-10000之间的数 N 的互质 ...
- sgu 102模拟欧拉函数
感觉自己弱爆了,做做SGU吧... #include<iostream> #include<cmath> //欧拉函数 using namespace std; int eul ...
- Coprimes - SGU 102(求互质数,水)
题目大意:给你一个正整数N,求出来不超过N 的并且与N互质的正整数的个数. 就是一个大水题~~~ 代码: #include<stdio.h> #include<string.h> ...
- SGU刷题之路开启
VJ小组:SGU---48h/题 每道做出的题目写成题解,将传送门更新在这里. SGU:101 - 200 SGU - 107 水题 解题报告 SGU - 105 找规律水题 解题报告 SGU - 1 ...
- (欧拉公式 很水) Coprimes -- sgu -- 1002
链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/B Coprimes 时限:250MS 内存:4096KB 6 ...
- SGU 乱搞日志
SGU 100 A+B :太神不会 SGU 101 Domino: 题目大意:有N张骨牌,两张骨牌有两面有0到6的数字,能相连当且仅当前后数字相同,问能否有将N张骨牌连接的方案?思路:裸的欧拉回路,注 ...
- 今日SGU 5.1
SGU 100 题意: 普通的a+b #include<bits/stdc++.h> #define de(x) cout<<#x<<"="&l ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
随机推荐
- WebService到底是什么?(转)
一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...
- Android Studio添加aar包依赖
1.将aar包考入需要依赖的模块的libs目录下 2.在需要依赖的模块的build.gradle中添加如下内容: dependencies { compile(name:'aar包名不带扩展名', e ...
- 使用checked关键字处理“溢出”错误
在进行算术运算时,可以使用checked关键字有效处理溢出错误,使用checked关键字可能对程序的性能会有一点点的影响,这是一种以牺牲性能换取健康的做法. private void button1_ ...
- 安装Oracle11g时,检测到系统的主 IP 地址是 DHCP 分配的地址
检查完成.此次检查的总体结果为: 失败 <<<< 问题: 安装检测到系统的主 IP 地址是 DHCP 分配的地址. 建议案: Oracle 支持在具有 DHCP 分配的 IP ...
- jdk 1.6 & 1.7新特性
jdk1.6新特性 1.Desktop类和SystemTray类 2.使用JAXB2来实现对象与XML之间的映射 3.StAX 4.使用Compiler API 5.轻量级Http Server AP ...
- HTTP网页错误代码大全带解释
HTTP网页错误代码大全带解释 HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败HTTP 401.2 - 未授权:服务器配置问题导致登录失败HTTP 401.3 - ACL 禁 ...
- [笔记]一个测试浏览器对html5支持的网站
用需要测试的浏览器打开这个地址:http://html5test.com/
- 24.task的运用
任务就是一段封装在“task-endtask”之间的程序.任务是通过调用来执行的,而且只有在调用时才执行,如果定义了任务,但是在整个过程中都没有调用它,那么这个任务是不会执行的.调用某个任务时可能需要 ...
- 【 Regular Expression Matching 】cpp
题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...
- 两个SVN仓库之间代码的转移
背景: 1.公司的svn服务器架设在了公司内网环境中,没有公网ip,所以离开了公司环境就无法访问(更新.提交...)svn服务器了: 2.四个开发人员去客户现场开发新的需求,在现场找了一台服务器临时搭 ...