【规律】Farey Sums
时间:2019-08-21
本文章向大家介绍【规律】Farey Sums,主要包括【规律】Farey Sums使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
【参考博客】:
https://blog.csdn.net/meopass/article/details/82952087
Farey Sums
题目描述
Given a positive integer, N, the sequence of all fractions a/b with (0 < a ≤ b), (1 < b ≤ N) and a and b relatively prime, listed in increasing order, is called the Farey Sequence of order N.
For example, the Farey Sequence of order 6 is:
For example, the Farey Sum of order 6 is:
For example, the Farey Sequence of order 6 is:
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
If the denominators of the Farey Sequence of order N are:b[1], b[2], . . . , b[K]
then the Farey Sum of order N is the sum of b[i]/b[i + 1] from i = 1 to K—1.For example, the Farey Sum of order 6 is:
1/6 + 6/5 + 5/4 + 4/3 + 3/5 + 5/2 + 2/5 + 5/3 + 3/4 + 4/5 + 5/6 + 6/1 = 35/2
Write a program to compute the Farey Sum of order N (input).输入
The first line of input contains a single integer P, (1 ≤ P ≤ 10000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input. It contains the data set number, K, followed by the order N, (2 ≤ N ≤ 10000), of the Farey Sum that is to be computed.
Each data set consists of a single line of input. It contains the data set number, K, followed by the order N, (2 ≤ N ≤ 10000), of the Farey Sum that is to be computed.
输出
For each data set there is a single line of output. The single output line consists of the data set number,K, followed by a single space followed by the Farey Sum as a decimal fraction in lowest terms. If the denominator is 1, print only the numerator.
样例输入
4
1 6
2 15
3 57
4 9999
样例输出
1 35/2
2 215/2
3 2999/2
4 91180457/2
参考博客:
别人博客的推导公式:
我倒是觉得,这个题目就是找规律。因为看到答案都是分母为2,很容易想到其实这个题目就是找规律有关的。
联系互素就想到欧拉函数。写出前几个出来发现就是 ( 3phi(x) - 1 ) / 2
1 #pragma GCC optimize("Ofast,no-stack-protector") 2 #pragma GCC optimize("O3") 3 #pragma GCC optimize(2) 4 #include <bits/stdc++.h> 5 #define inf 0x3f3f3f3f 6 #define linf 0x3f3f3f3f3f3f3f3fll 7 #define pi acos(-1.0) 8 #define nl "\n" 9 #define pii pair<ll,ll> 10 #define ms(a,b) memset(a,b,sizeof(a)) 11 #define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 12 using namespace std; 13 typedef long long ll; 14 const int mod = 998244353; 15 ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;} 16 //ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;} 17 inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;} 18 19 const int N = 1e4+5; 20 21 ll pki[N]; 22 23 void get_pki() 24 { 25 for(int i=1;i<N;i++) pki[i] = i; 26 for(int i=2;i<N;i++){ 27 if(pki[i]==i)for(int j=i;j<N;j+=i) 28 pki[j]=pki[j]/i*(i-1); 29 pki[i] += pki[i-1]; 30 } 31 } 32 33 int main() 34 { 35 get_pki(); 36 int _, cas, n; 37 for(scanf("%d",&_);_--;) 38 { 39 scanf("%d",&cas); 40 scanf("%d",&n); 41 printf("%d %lld/2\n",cas,3*pki[n]-1); 42 43 } 44 45 }
原文地址:https://www.cnblogs.com/Osea/p/11387238.html
- Java内存管理
- python基础知识——内置数据结构(字典)
- mysql、mongodb、python(dataframe).聚合函数的形式,以及报错解决方案
- JavaScript计算水仙花数【可自定义范围】
- JSP简单入门(1)
- mongodb取出json,利用python转成dataframe(dict-to-dataframe)
- JSP简单入门(2)
- JSP简单入门(3)
- 物化视图相关的性能改进 (r7笔记第58天)
- Maven 核心原理解析(1)
- LeetCode——Two Sum
- TensorFlow全新的数据读取方式:Dataset API入门教程
- 不经意发现的dba_objects和dba_tables中的细节(r7笔记第56天)
- LeetCode——Longest Substring Without Repeating Characters
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法