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. ...
随机推荐
- 推荐一个sqlce,sqllite等数据库管理工具
推荐一个sqlce,sqllite等数据库管理工具 下载地址: http://fishcodelib.com/files/DatabaseNet4.zip 支持sqlserver,sqlce, sql ...
- find your present
Description In the present, and their card numbers are , , , , .so your present will be the one with ...
- Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- VBA赋值给指定单元格
这是一个Range对象基本操作实例,对指定单元格赋值,然后使用弹窗获取值. 代码如下: Sub test1() Worksheets( MsgBox "工作表Sheet1内单元格A5中的值为 ...
- AFNetworking 2.0 使用
AFNetworking 下载地址:https://github.com/AFNetworking/AFNetworking/ AFNetworking 2.0 当Deployment Target ...
- squid基础配置
1 2 3 4 5 6 7 8 9 10 vim /etc/squid/squid.conf http_port 192.168.1.12:3128 (可写多个) cache_mem 64MB ...
- 利用while(code!=EOF){}来实现“无限”循环
#include <stdio.h>int main(){ char a,b,c; char t; while(scanf("%c%c%c",& ...
- shell基本语法备忘
1.第一行要写明shell种类 #!/bin/bash 2.打印输出 #!/bin/bashecho "Hello World !~" 3.变量定义 变量=前后不能有空格, ...
- 高效线程池(threadpool)的实现
高效线程池(threadpool)的实现 Nodejs编程是全异步的,这就意味着我们不必每次都阻塞等待该次操作的结果,而事件完成(就绪)时会主动回调通知我们.在网络编程中,一般都是基于Reactor线 ...
- Notes of the scrum meeting(12.8)
meeting time:18:00~18:30p.m.,December 8th,2013 meeting place:20号公寓前 attendees: 顾育豪 ...