A fraction m / n is basic if 0 ≤ m < n and it is irreducible if gcd(m, n) = 1. Given a positive integer n, in  this problem you are required to find out the number of irreducible basic fractions with denominator n.  

For example, the set of all   basic  fractions   with denominator 12,  before reduction to lowest terms,  is

Reduction yields

Hence there are only the following 4 irreducible basic fractions with denominator 12

Input

Each line of the input contains a positive integer n (< 1000000000) and the input terminates with avalue 0 for n (do not process this terminating value).

Output

For each n in the input print a line containing the number of irreducible basic fractions with denominator n.

Sample Input

12

123456

7654321

0

Sample Output

4

41088

7251444

问题链接:UVA10179 Irreducable Basic Fractions

问题简述:(略)

问题分析

  这是一个数论问题。

  给定一个正整数n,求在[1, n]区间内和n互质的正整数的个数。直接使用欧拉函数进行计算。

程序说明:(略)

题记:(略)

参考链接:欧拉函数

AC的C语言程序如下:

/* UVA10179 Irreducable Basic Fractions */#include <stdio.h>/* 欧拉函数 */
int phi(int n)
{int ret=1, i;for(i=2; i*i<=n; i++) {if(n%i == 0) {n /= i;ret *= i-1;while(n%i == 0) {n /= i;ret *= i;}}}if(n>1)ret *= n-1;return ret;
}int main(void)
{int n;while(~scanf("%d", &n) && n)printf("%d\n", phi(n));return 0;
}

 

UVA10179 Irreducable Basic Fractions【欧拉函数+数论】相关推荐

  1. P2158,jzoj1709-仪仗队【欧拉函数,数论】

    正题 评测记录:https://www.luogu.org/recordnew/lists?uid=52918&pid=P2158 大意 有n∗nn∗nn*n个点,求从(1,1)(1,1)(1 ...

  2. Bzoj 2749: [HAOI2012]外星人 欧拉函数,数论,线性筛

    2749: [HAOI2012]外星人 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 568  Solved: 302 [Submit][Status ...

  3. jzoj1164-求和【欧拉函数,数论】(筛欧拉函数模板)

    正题 大意 给出一个nnn,求1∼n" role="presentation" style="position: relative;">1∼n1 ...

  4. HDU 5514 Frogs(欧拉函数+数论YY)

    传送门 Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  5. hdu1395 数论 欧拉函数

    hdu1395 数论   欧拉函数 对于给出的每一个n 求最小正整数 x 满足 2^x mod n = 1 1.如果给出的n 是偶数或者 1 则一定无解 2.如果是奇数 首先根据欧拉定理 我们可知 p ...

  6. 数论一之定理证明——裴蜀/威尔逊/费马/扩展欧几里得/[扩展]欧拉/[扩展]中国剩余定理,欧拉函数,逆元,剩余系,筛法

    打死没想到会在H老师处学懂数论 同余,整除 模运算 埃式筛法 欧拉筛法 最大公约数和最小公倍数 辗转相除法 更相减损术 裴蜀定理 威尔逊定理 费马定理 同余等价类.剩余系.缩系 欧拉函数 欧拉定理 扩 ...

  7. 【计蒜客 - 蓝桥训练】欧拉函数(数学,数论,模板)

    题干: 在数论中,对正整数 nn,欧拉函数 \varphi (n)φ(n) 是小于等于 nn 的正整数中与 nn 互质的数的数目. 例如 \varphi (12)=4φ(12)=4,因为 1,5,7, ...

  8. matlab狄利克雷函数,数论入门1——莫比乌斯函数,欧拉函数,狄利克雷卷积,线性筛,莫比乌斯反演,杜教筛...

    数论入门1 一个菜鸡对数论的一点点理解... 莫比乌斯函数 定义函数$\mu(n)$为: 当n有平方因子时,$\mu(n)=0$. 当n没有平方因子时,$\mu(n)=(-1)^{\omega(n)} ...

  9. 数论讨伐!欧拉函数!

    [欧拉函数] 任务开始. 什么是欧拉函数?我们又怎么求呢??? 此次任务的主要怪物:欧拉函数 (1)欧拉函数定义 欧拉函数嘛,当然是我们著名的莱昂哈德·欧拉发明的啦~那么他是怎么定义介个函数滴? 咳咳 ...

最新文章

  1. Linux Centos 上一些常用的命令
  2. 【队列源码研究】消息队列beanstalkd源码详解
  3. ML之多分类预测:以某个数据集为例从0到1深入理解科学预测之多分类问题的思路框架
  4. 数据表从一个表空间中移动到另一个表空间中
  5. Scrapy源码阅读分析_1_整体框架和流程介绍
  6. image pil 图像保存_如何利用python中的PIL库做图像处理?
  7. 解决RabbitMQ service is already present - only up...
  8. 使用JS提交form表单和w3c标准
  9. Java SSM框架学习之Mybatis篇
  10. 强大的导航网站,做设计必备!
  11. Spring Boot 学习之表单验证
  12. checkbox属性checked=checked已有,但却不显示打勾的解决办法
  13. auto cad 打印颜色变浅_CAD初学者最容易忽视的CAD打印线宽问题,你“中枪”了吗?...
  14. DSP28335看门狗复位
  15. 数据权限设计思路_权限设计数据权限
  16. 7月书讯(下)| 宝藏新书助你“乘风破浪”
  17. Python编程快速上手 让繁琐工作自动化 豆瓣评分[9.00]
  18. 中国物流企业家谈“物流”
  19. Python实现base64编码文件转化为jpg/png/jpeg/格式图片
  20. 如何使用 Django 进行分页

热门文章

  1. 开源GIS(十七)——OGC标准
  2. 缓冲区分析—ArcGIS API for JavaScript
  3. Docker Swarm 入门
  4. 怎么做游戏打击感浅述
  5. Adobe AIR * 设置移动应用程序属性
  6. 网游Server端开发基础
  7. 如何打开电脑就自动显示html文件,电脑教程:Win10怎么打开html文件
  8. pandas将某列复制到另一个表_使用pandas将列从一个数据帧复制到另一个数据帧的最快方法?...
  9. scala中的filter函数
  10. 从集合(内存)中创建RDD