(Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called a reduced proper fraction.
If we list the set of reduced proper fractions for d 8 in ascending order of size, we get:
1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
It can be seen that there are 3 fractions between 1/3 and 1/2.
How many fractions lie between 1/3 and 1/2 in the sorted set of reduced proper fractions for d 12,000?
题目大意:
考虑分数 n/d, 其中n 和 d 是正整数。如果 nd 并且最大公约数 HCF(n,d)=1, 它被称作一个最简真分数。
如果我们将d 8的最简真分数按照大小的升序列出来,我们得到:
1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
可以看出1/3和1/2之间共有3个分数。
在d 12,000的升序真分数列表中,1/3和1/2之间有多少个分数?
//(Problem 73)Counting fractions in a range
// Completed on Wed, 19 Feb 2014, 16:34
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#define N 12000 int gcd(int a, int b) //求最大公约数函数
{
int r;
while(b) {
r = a % b;
a = b;
b = r;
}
return a;
} void solve()
{
int a, b, i, j, ans;
ans = ;
for(i = ; i <= N; i++) {
a = i / ; b = i / ;
for(j = a + ; j < b + ; j++) {
if(gcd(i, j) == )
ans++;
}
}
printf("%d\n", ans);
} int main()
{
solve();
return ;
}
Answer:
|
7295372 |
(Problem 73)Counting fractions in a range的更多相关文章
- (Problem 72)Counting fractions
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
随机推荐
- 数据结构中La表的数据合并到Lb表中
实验描述:La表中的数据为(3,5,8,11) Lb 表中的数据为(2,6,8,9,11,15,20) 将La表中的数据而不存在Lb表的数据插入到Lb表中,从而实现并集操作. 出现的问题:最后实现的 ...
- golang 并发之协程及通道
一.概述 在golang中,每个并发执行单元称为goroutine,当程序启动时,main函数在一个单独的goroutine中运行,(main goroutine).新的goroutine会用go语句 ...
- Java日期计算之Joda-Time
http://rensanning.iteye.com/blog/1546652 Joda-Time提供了一组Java类包用于处理包括ISO8601标准在内的date和time.可以利用它把JDK D ...
- nginx install lua module
#install luajit #http://luajit.org/download.html .tar.gz cd LuaJIT- make install PREFIX=/home/allen. ...
- poj 1321 棋盘问题 递归运算
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19935 Accepted: 9933 Description ...
- ThinkPHP实现导出
刚开始做项目的时候,遇到了这个需求.说实话,对于一个才出来实习的菜鸟,而且还是才接触PHP的菜鸟而言,实在是有心杀敌,无力回天啊. 最简单的方法,就是网上找一个插件,然后一个本来就十几兆的项目,又增加 ...
- PHP弱类型:WordPress Cookie伪造
1 PHP弱类型 PHP是弱类型语言,所以变量会因为使用场景的不同自动进行类型转换.PHP中用 == 以及 != 进行相等判断时,会自动进行类型转换,用 === 以及 !== 进行判断时不会自动转换类 ...
- WL(Wear leveling)磨损平衡
前面说过,闪存寿命是以P/E次数来计算的,而WL就是确保闪存内每个块被写入的次数相等的一种机制.若没有这个机制,SSD内的闪存颗粒就无法在同一时间内挂掉,那对用户来说就是灾难. 会出现这种 ...
- 2015 8月之后"云计算"学习计划
1. 自己在家搭建openstack,使用RDO搭建自己的openstack环境,不必源码方式搭建,只要搭建起来就好,越快越好 --以RDO方式,搭建一个all-in-one的主机,只需要租一台虚拟机 ...
- centos 修改shm
Linux下,Oracle 11g的自动内存管理不能指定大于这个/dev/shm的总量内存.否则就会出现如下错误 ORA-00845: MEMORY_TARGET not supported on t ...