(欧拉公式 很水) Coprimes -- sgu -- 1002
链接:
http://vj.acmclub.cn/contest/view.action?cid=168#problem/B
Coprimes
问题描述
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)是所有小于n的正整数里,和n互素的整数的个数。n是一个正整数。
欧拉证明了下面这个式子:
如果n的标准素因子分解式是p1^a1*p2^a2*……*pm^am,其中众pj(j=1,2,……,m)都是素数,而且两两不等。则有
φ(n)=n(1-1/p1)(1-1/p2)……(1-1/pm)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue> using namespace std; #define INF 0x3f3f3f3f
#define N 11000 int a[N], vis[N], cnt; void IN()
{
int i, j;
cnt = ; memset(a, , sizeof(a));
memset(vis, , sizeof(vis)); for(i=; i<N; i++)
{
if(!vis[i])
{
a[cnt++] = i;
for(j=i+i; j<N; j+=i)
vis[j] = ;
}
}
} int main()
{
int n; IN(); while(scanf("%d", &n)!=EOF)
{
int i=, aa[N]={}, bnt = , m; m = n;
while(a[i]<=m)
{
if(m%a[i]==)
{
m /= a[i];
if(a[i]!=aa[bnt-])
aa[bnt++] = a[i];
}
else
i++;
} for(i=; i<bnt; i++)
n = n-n/aa[i]; printf("%d\n", n);
} return ;
}
我醉了,其实可以这么简单
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue> using namespace std; #define INF 0x3f3f3f3f
#define N 11000 int gcd(int a, int b)
{
return b==?a:gcd(b, a%b);
} int main()
{
int n; while(scanf("%d", &n)!=EOF)
{
int sum = ;
for(int i=; i<=n; i++)
{
if(gcd(i, n)==)
sum ++;
}
printf("%d\n", sum);
} return ;
}
(欧拉公式 很水) Coprimes -- sgu -- 1002的更多相关文章
- 【jQuery基础学习】09 jQuery与前端(这章很水)
这章主要是将如何将jQuery应用到网站中,或者说其实就是一些前端知识,对于我这种后端程序来说其实还是蛮有用的. 关于网站结构 文件结构 前端文件分三个文件夹放 images文件夹用来存放将要用到的图 ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 236A,虽然很水,但有一个很简单的函数用起来方便
A. Boy or Girl time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- FZU 2205 据说题目很水
2205 据说题目很水 Accept: 199 Submit: 458Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Descr ...
- Coprimes - SGU 102(求互质数,水)
题目大意:给你一个正整数N,求出来不超过N 的并且与N互质的正整数的个数. 就是一个大水题~~~ 代码: #include<stdio.h> #include<string.h> ...
- hdu 3295 模拟过程。数据很水
An interesting mobile game Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Ja ...
- FZUOJ 2205 据说题目很水 (无三元环图最大边数)
Problem Description Sunday最近对图论特别感兴趣,什么欧拉回路什么哈密顿回路,又是环又是树.在看完一本书后,他对自己特别有信心,便找到大牛牛犇犇,希望他出一题来考考自己. 在遥 ...
- 2753:走迷宫(dfs+初剪)//可以说是很水了。。。
总时间限制: 1000ms 内存限制: 65536kB 描述 一个迷宫由R行C列格子组成,有的格子里有障碍物,不能走:有的格子是空地,可以走.给定一个迷宫,求从左上角走到右下角最少需要走多少步(数 ...
- POJ 2080 Calendar(很水的模拟)
刚开始一直WA,才发现原来代码中两处减去年份.月份的天数的判断条件用的是>=,虽然最后考虑n=0要退回一天的情况,但还是WA.后来改成>的条件判断,省去了考虑n=0的麻烦,AC. 此题无非 ...
- 一年前的很水的渣网页(第一次html试水)
<!doctype html> <html lang="zh-cn"> <base target="_blank" /> & ...
随机推荐
- denyhosts配置详解
DenyHosts官方网站为:http://denyhosts.sourceforge.net 用DenyHosts可以阻止试图猜测SSH登录口令,它会分析/var/log/secure等日志文件,当 ...
- dll is in timestamps but is not known in guidmapper… 错误
解决方法是:在Assets下右键,Reimport All
- How to Pronounce INTERNATIONAL
How to Pronounce INTERNATIONAL Share Tweet Share Tagged With: Dropped T How do you pronounce this lo ...
- Session保存数据
int nameid=dao.isLegalUser(name, password);/ /方法返回int数据 request.setAttribute("nam ...
- CentOS7系列搭建Openvpn
环境:CentOS Linux release 7.3.1611 (Core) 查看os版本命令:[root@openvpn ~]# cat /etc/redhat-release 命令记录如下: y ...
- 大型运输行业实战_day02_1_数据库设计与powerDesigner使用
1.安装powerDesigner 1. 傻瓜式的安装 2.在安装的过程中选择地区后才可以点击同意和下一步 3.安装地址,建议直接把c改为d 4.其他选项直接下一步 2.使用powerDesigner ...
- Mo2C-tag
记者今天从中国科学院金属研究所获悉,该所沈阳材料科学国家(联合)实验室先进炭材料研究部任文才研究组在大尺寸高质量二维过渡族金属碳化物晶体的制备与物性研究方面取得了重要突破.相关成果日前在<自然— ...
- 5.Longest Palindromic Substring (String; DP, KMP)
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- sqlserver2008debug存储过程
新建一个查询窗口,exec proc_name params…… 然后启动调试 右侧可以选择“逐过程”“逐语句”“跳出”,下方展示变量的值 参考文章:https://www.cnblogs.com/s ...
- win7安装SQL2005出现29506错误
解决方法: 假设下载的文件名为SQLServer2005_SSMSEE.msi ,并且放在F盘根目录下, 新建一个文本文件,输入msiexec /i F:\SQLServer2005_SSMSEE.m ...