[数学-farey序列]Pku3374--Cake Share
来源:互联网 发布:安卓c语言编程软件 编辑:程序博客网 时间:2024/05/16 14:27
http://acm.pku.edu.cn/JudgeOnline/problem?id=3374
Description
Updog prepared to enjoy his delicious supper. At the very time he was ready to eat, a serious accident occurred—GtDzx appeared!! GtDzx declared his hadn't eaten anything for 3 days (obviously he was lying) and required Updog to share the cake with him. Further more, he threatened Updog that if Updog refused him, he would delete Updog's account in POJ! Thus Updog had no choice.
Updog intended to cut the cake into s (s ≥ 1) pieces evenly, and then gave t(0≤ t ≤ s) pieces to GtDzx. Apparently GtDzx might get different amount of cake for different s and t. Note that s = 12, t = 4 and s = 6, t = 2 will be regarded as the same case since GtDzx will get equal amount in the two cases. Updog wouldn't separate the cake into more than N pieces.
After sorted all available cases according to the amount of cake for GtDzx, in the first case no cake to gave to GtDzx (t = 0) and in the last case GtDzx would get the whole cake (s = t). Updog wondered that how much cake GtDzx would get in the k-th case.
Input
The first line of the input file contains two integers N (1 ≤ N ≤ 5000) and C(0 ≤ C≤ 3000). The following C lines each contains a positive integer describe C query respectively. The i-th query ki is to ask GtDzx's share of whole cake in the ki-th case .
Output
Answer each query in a separated line, according to the order in the input.
Sample Input
5 4 171112
Sample Output
0/13/51/1No Solution
Source
题目大意:让你找出,分子分母均不大于N的最简真分数中,第k小的是什么。
分析:分子分母均不大于N的最简真分数序列,在数学上称为farey序列,用FN表示。
例如:F3=(0/1,1/3,2/1,2/3,1/1)。
这个序列有以下特征:
1、除了F1,FN序列的分数个数为奇数个,且中间一个必然为1/2,序列左右对称,相对应的两个分数和为1.
2、对于三个连续的分数x1/y1,x2/y2,x3/y3,有x2=x1+x3,y2=y1+y3且x1*y2-x2*y1=1。这保证了序列中的分数都是最简分数。
由性质2,可以得出以下的一个递归构造farey序列的算法:
Procedure make_farey(x1,y1,x2,y2 : integer)
就这么简单。
其中x1,y1,x2,y2表示第一个分数和第三个分数。
有了这个构造算法,这题就迎刃而解了。
只要构造出序列的前半部分,然后根据性质1,不难得出后半部分。
F5000大约有7600000个数。所以一半只要开4000000就完全足够了。
codes:
- [数学-farey序列]Pku3374--Cake Share
- poj 3374 Cake Share(Farey序列第k大)
- Farey序列
- Farey序列
- POJ 3374 Cake Share 可能会
- farey序列构建 c++
- Farey序列构造和查找
- Farey Sequence法里序列
- PE 71 72 73 Farey Neighbours (sequence) (farey序列)
- 【gcd+数学证明】【HDU1722】 CAKE
- hdu 1722 Cake 数学yy
- HDU 1722 Cake【规律+数学】
- HDU 1722 Cake (GCD+数学)
- [数学-欧拉函数]Pku2478--Farey Sequence
- 数学训练----数论F - Farey Sequence
- Pick定理及Farey序列学习小记
- Farey序列与Stern-Brocot树
- [hoj 1076]Ordered Fractions[Farey序列]
- 《Microsoft Sql server 2008 Internals》读书笔记--第五章Table(6)
- 在Ogre中载入OgreMax场景文件的方法
- 详细讲解在Spring中进行集成测试
- PHP基本语法(四)—— switch语句
- 无线模块在物联网中的作用
- [数学-farey序列]Pku3374--Cake Share
- 《高质量程序设计指南---C++/C语言》 下载
- PHP基本语法(五)—— 循环语句
- [C++]String类的实现
- 面试标准C++编程总结
- 创业家杂志:美国没史玉柱 中国没乔布斯
- 新东方英语
- C++的auto_ptr
- PHP基本语法(六)—— 数组