链接:

http://vj.acmclub.cn/contest/view.action?cid=168#problem/B

Coprimes

时限:250MS     内存:4096KB     64位IO格式:%I64d & %I64u

问题描述

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的更多相关文章

  1. 【jQuery基础学习】09 jQuery与前端(这章很水)

    这章主要是将如何将jQuery应用到网站中,或者说其实就是一些前端知识,对于我这种后端程序来说其实还是蛮有用的. 关于网站结构 文件结构 前端文件分三个文件夹放 images文件夹用来存放将要用到的图 ...

  2. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 236A,虽然很水,但有一个很简单的函数用起来方便

    A. Boy or Girl time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. FZU 2205 据说题目很水

    2205 据说题目很水 Accept: 199    Submit: 458Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Descr ...

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

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

  5. hdu 3295 模拟过程。数据很水

    An interesting mobile game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Ja ...

  6. FZUOJ 2205 据说题目很水 (无三元环图最大边数)

    Problem Description Sunday最近对图论特别感兴趣,什么欧拉回路什么哈密顿回路,又是环又是树.在看完一本书后,他对自己特别有信心,便找到大牛牛犇犇,希望他出一题来考考自己. 在遥 ...

  7. 2753:走迷宫(dfs+初剪)//可以说是很水了。。。

    总时间限制:  1000ms 内存限制:  65536kB 描述 一个迷宫由R行C列格子组成,有的格子里有障碍物,不能走:有的格子是空地,可以走.给定一个迷宫,求从左上角走到右下角最少需要走多少步(数 ...

  8. POJ 2080 Calendar(很水的模拟)

    刚开始一直WA,才发现原来代码中两处减去年份.月份的天数的判断条件用的是>=,虽然最后考虑n=0要退回一天的情况,但还是WA.后来改成>的条件判断,省去了考虑n=0的麻烦,AC. 此题无非 ...

  9. 一年前的很水的渣网页(第一次html试水)

    <!doctype html> <html lang="zh-cn"> <base target="_blank" /> & ...

随机推荐

  1. UEFI BIOS和普通BIOS的区别

    作为传统BIOS(Basic Input/Output System)的继任者,UEFI拥有前辈所不具备的诸多功能,比如图形化界面.多种多样的操作方式.允许植入硬件驱动等等.这些特性让UEFI相比于传 ...

  2. PageUtil 分页

    /** * 分页工具类 * @author Administrator * */ public class PageUtil { /** * 生成分页代码 * @param targetUrl 目标地 ...

  3. CentOS开机卡在进度条,无法正常开机的排查办法

    CentOS开机的时候卡在进度条一直进不去 重启,按f5键进度条/命令行界面方式切换,确认卡问题后处理就好 我这边卡在redis服务,设置为开机启动但是一直服务启动不起来 重启按住"e&qu ...

  4. iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 解析JSON

    视频地址:https://www.cctalk.com/v/15114923886141 JSON 数据 我颠倒了整个世界,只为摆正你的倒影. 前面的文章中,我们已经完成了项目中常见的问题,比如 路由 ...

  5. python处理分隔大文件

    4个.sql格式的文件,2G大小,直接插入mysql数据中,文件太大了,导入不进去. 太大的文件用python处理也很麻烦,处理不了,只能先分隔成小文件处理. 文件中数据格式:其中values里面的数 ...

  6. too few PGs per OSD (20 < min 30)

    ceph osd pool set replicapool pg_num 150 ceph osd pool set replicapool pgp_num 150

  7. web中的中文乱码处理

    1.页面设置pageEncoding="UTF-8" <%@ page contentType="text/html;charset=UTF-8" lan ...

  8. 在c#下用 WCF编写restful

    1.添加WCF服务库 2.在global里面注册路由 RouteTable.Routes.Add(new ServiceRoute("api", new WebServiceHos ...

  9. 记一次spring-session登录后失效的问题

    用户登录后,可以进入页面,但ajax请求或跳转其他页面时,会被当做匿名用户,即没有登录.查看session数据库,发现多出两条session,一条为正常数据,里面有对应的用户名:另一条为异常的数据,没 ...

  10. sql server profiler 的使用

    sql server profiler  是作为监听sql语句执行的软件, 主要是看NTUserName,system是系统的,看自己数据库的名字.