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

  1. (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 ...

  2. (Problem 33)Digit canceling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...

  3. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

  4. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  5. (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 ...

  6. (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 ...

  7. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  8. (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 ...

  9. (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 ...

随机推荐

  1. 程序猿的量化交易之路(20)--Cointrader之Assert实体(8)

    转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top 不论什么可交易的都能够称之为Assert,资产.其类代码例如以下: pac ...

  2. vs2010调试快捷键

    VS2010单步调试  1.设置断点 F9设置或者取消断点,如果当前行未设置断点,则F9可以再当前行设置断点,如果已经设置,则为去除断点   2.单步调试 F10不进入函数单步,F11进入函数单步 , ...

  3. JavaScript之面向对象学习五(JS原生引用类型Array、Object、String等等)的原型对象介绍

    1.原型模式的重要性不仅仅体现在创建自定义类型方面,就连所有的原生的引用类型(Obejct.Array.String等等)都在构造函数的原型上定义方法和属性.如下代码可以证明: alert(typeo ...

  4. WPF利用依赖属性和命令编写自定义控件

    以实例讲解(大部分讲解在代码中) 1,新建一个WPF项目,添加一个用户控件之后在用户控件里面添加几个控件用作测试, <UserControl x:Class="SelfControlD ...

  5. events模块

    /** * Created by Administrator on 2016/8/3. */ var http = require("http"); //Node 导入文件系统模块 ...

  6. C++_基础_继承、多态

    内容: (1)子类中的拷贝构造和拷贝赋值 (2)多继承和虚继承 (3)多态的初识 (4)虚析构的特性和使用 (5)多态的底层实现 (6)纯虚函数.抽象类的概念 1.子类中的拷贝构造和拷贝赋值 子类中的 ...

  7. XLSReadWrite控件简介

    2015-10-22  23:57:55 原帖地址:http://www.cnblogs.com/dabiao/archive/2011/07/08/2100609.html XLSReadWrite ...

  8. windows8 安装IIS 和 添加网站(转)

    Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...

  9. 模块化定义JS,让统一文件夹内相同的变量不冲突

    两种方法: 1.(function(){……编写代码……})()   //先声明一个函数,声明完后直接调用 2.!function(){……编写代码……}()

  10. JS计算两个日期相差几天

    function Computation(sDate1, sDate2){ var aDate, oDate1, oDate2, iDays aDate = sDate1.split("-& ...