n阶的法里数列是0和1之间最简分数数列,由小至大排列,每个分数的分母不大于n

Stern-Brocot树(SB Tree)可以生成这个序列

{0/1,1/1}
{0/1,1/2,1/1}
{0/1,1/3,1/2,2/3,1/1}
{0/1,1/4,1/3,1/2,2/3,3/4,1/1}
{0/1,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,1/1}
{0/1,1/6,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,5/6,1/1}
{0/1,1/7,1/6,1/5,1/4,2/7,1/3,2/5,3/7,1/2,4/7,3/5,2/3,5/7,3/4,4/5,5/6,6/7,1/1}
{0/1,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/1}
{0/1,1/9,1/8,1/7,1/6,1/5,2/9,1/4,2/7,1/3,3/8,2/5,3/7,4/9,1/2,5/9,4/7,3/5,5/8,2/3,5/7,3/4,7/9,4/5,5/6,6/7,7/8,8/9,1/1}
{0/1,1/10,1/9,1/8,1/7,1/6,1/5,2/9,1/4,2/7,3/10,1/3,3/8,2/5,3/7,4/9,1/2,5/9,4/7,3/5,5/8,2/3,7/10,5/7,3/4,7/9,4/5,5/6,6/7,7/8,8/9,9/10,1/1}

Farey sequences UVA - 10408

求n阶Farey sequences的第k项,找到下一项的递推式,也就是基本不等式

#include <stdio.h>
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
int a0=,a1=,b0=,b1=n,a2,b2;
for(int i=;i<k;i++){
int c=(n+b0)/b1;
a2=c*a1-a0;
b2=c*b1-b0;
a0=a1,a1=a2;
b0=b1,b1=b2;
}
printf("%d/%d\n",a1,b1);
}
return ;
}

X - Farey Sequence

The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are 
F2 = {1/2} 
F3 = {1/3, 1/2, 2/3} 
F4 = {1/4, 1/3, 1/2, 2/3, 3/4} 
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}

You task is to calculate the number of terms in the Farey sequence Fn.

Input

There are several test cases. Each test case has only one line, which contains a positive integer n (2 <= n <= 10 6). There are no blank lines between cases. A line with a single 0 terminates the input.

Output

For each test case, you should output one line, which contains N(n) ---- the number of terms in the Farey sequence Fn. 

Sample Input

2
3
4
5
0

Sample Output

1
3
5
9

这个函数的个数有个近似值,但是这个要求准确的个数,这个个数也没什么规律

Fn是分母是小于n的,而且其他和他互质,欧拉函数是积性函数,所以欧拉函数求下前缀和就行了

E(x)表示比x小的且与x互质的正整数的个数,也就是欧拉函数

#include <stdio.h>
const int N=1e6+;
typedef __int64 ll;
int phi[N],prime[N];
ll sum[N];
bool vis[N];
void Euler()
{
phi[]=;
int cnt=;
for(int i=;i<=1e6;i++)
{
if(!vis[i]){prime[++cnt]=i;phi[i]=i-;}
for(int j=;j<=cnt&&prime[j]*i<=1e6;j++)
{
vis[prime[j]*i]=;
if(i%prime[j])phi[prime[j]*i]=phi[i]*(prime[j]-);
else {phi[prime[j]*i]=phi[i]*prime[j];break;}
}
}
}
int main()
{
Euler();sum[]=;
for(int i=;i<=1e6;i++)
sum[i]+=sum[i-]+phi[i];
int n;
while(~scanf("%d",&n)){
if(!n)break;
printf("%I64d\n",sum[n]);
}
return ;
}

2866: Farey Sequence Again 

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
总提交: 14            测试通过:7

描述

The Farey sequence Fn for any positive integer n is the set of irreducible rational numbers a/b with 0<a<b<=n and (a, b) = 1 arranged in increasing order. Here (a, b) mean the greatest common divisor of a and b. For example:
            F2 = {1/2}
            F3 = {1/3, 1/2, 2/3}
      Given two positive integers N and K, with K less than N, you need to find out the K-th smallest element of the Farey sequence FN.

输入

The first line of input is the number of test case T, 1<=T<=1000. Then each test case contains two positive integers N and K. 1<=K<N<=10^9.

输出

For each test case output the Kth smallest element of the Farey sequence FN in a single line.

样例输入

样例输出

题目来源

Asia Chengdu Pre 2008

这个题是真的难啊,想了想查了查相关资料都做不了,最后竟然是利用这个级数增长很快,能互质的1,2,3用完就到1e9了,根本到不了n,贼鸡儿难想,%大佬,TOJ也有高人啊

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 ≥ 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 = 12, = 4 and = 6, = 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 (= 0) and in the last case GtDzx would get the whole cake (= 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 (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
1
7
11
12

Sample Output

0/1
3/5
1/1
No Solution

这个题也是这个内容,但是也没那么难啊,存一下所有的查询就好了

Farey sequences的更多相关文章

  1. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. [Leetcode] Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  3. poj2478 Farey Sequence (欧拉函数)

    Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...

  4. POJ 2478 Farey Sequence

     名字是法雷数列其实是欧拉phi函数              Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  5. 论文阅读(Weilin Huang——【AAAI2016】Reading Scene Text in Deep Convolutional Sequences)

    Weilin Huang--[AAAI2016]Reading Scene Text in Deep Convolutional Sequences 目录 作者和相关链接 方法概括 创新点和贡献 方法 ...

  6. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  7. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  8. Python数据类型之“序列概述与基本序列类型(Basic Sequences)”

    序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...

  9. Extract Fasta Sequences Sub Sets by position

    cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' & ...

随机推荐

  1. 基于FPGA的DDS任意波形发生器设计

    一.简介       DDS技术最初是作为频率合成技术提出的,由于其易于控制,相位连续,输出频率稳定度高,分辨率高, 频率转换速度快等优点,现在被广泛应用于任意波形发生器(AWG).基于DDS技术的任 ...

  2. ProtoBuff3 unity_TCP网络发包解包&&消息订阅

    using Google.Protobuf; //using Google.Protobuf.Examples.AddPerson; using Google.Protobuf.WellKnownTy ...

  3. [神经网络]一步一步使用Mobile-Net完成视觉识别(三)

    1.环境配置 2.数据集获取 3.训练集获取 4.训练 5.调用测试训练结果 6.代码讲解 本文是第三篇,获取tfboard训练集. 前面我们拿到了所有图片对应的标注信息的xml文件,现在我们需要先把 ...

  4. springmvc 的原理分析

    1. 用户发送请求至前端控制器(DispatcherServlet) 2.DispatcherServlet 将受到的请求调用HandlerMapping 处理映射器 3.处理器映射器根据配置注解找到 ...

  5. Ubuntu系统Apache 2部署SSL证书

    几天前用Apache 2部署了一个静态网页,但通过域名访问时Google提示“不安全”,经了解,原来是缺少证书. 什么是SSL证书? SSL 是指安全套接字层,简而言之,它是一项标准技术,可确保互联网 ...

  6. oracle没有监听和监听程序无法找到适用于客户机连接的例程

    1.无监听,可以尝试下以下几种办法: 1)在net manager中重新配置监听.我的net manager监听点开不了,把ADMIN下的listener.ora删掉再去打开试试. 2)cmd中输入n ...

  7. webpack4 + vue多页面项目精细构建思路

    #构建思路 虽然当前前端项目多以单页面为主,但多页面也并非一无是处,在一些情况下也是有用武之地的,比如: 项目庞大,各个业务模块需要解耦 SEO更容易优化 没有复杂的状态管理问题 可以实现页面单独上线 ...

  8. 配置淘宝镜像,不使用怪异的cnpm

    npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...

  9. 【贪心】bzoj1592: [Usaco2008 Feb]Making the Grade 路面修整

    贪心的经典套路:替换思想:有点抽象 Description FJ打算好好修一下农场中某条凹凸不平的土路.按奶牛们的要求,修好后的路面高度应当单调上升或单调下降,也 就是说,高度上升与高度下降的路段不能 ...

  10. LeetCode之Weekly Contest 93

    第一题:二进制间距 问题: 给定一个正整数 N,找到并返回 N 的二进制表示中两个连续的 1 之间的最长距离. 如果没有两个连续的 1,返回 0 . 示例 1: 输入:22 输出:2 解释: 22 的 ...