- 2024-04-07Farey Sequence
多组测试数据,每组测试数据给你一个正整数\(n\),让你求满足\(\gcd(i,j)=1\)并且\(1\lei<j\len\)的数对个数。随便想一想,得出一个递推式:\(F_n=F_{n-1}+\varphi(n)\)。证明很简单:\(F_n\)是包含\(F_{n-1}\)的,多出来的部分就是小于\(n\)并且和\(n\)互质的数的个
- 2024-03-07P8058 [BalkanOI2003] Farey 序列 题解
分析考虑二分答案。对于当前二分的答案\(x\),设\(cnt\)表示Farey序列中\(\frac{p}{q}\lex\)的满足条件的数量。对于一组\((i,j)\),若\(\frac{j}{i}\lex\),则\(j\le\lfloori\timesx\rfloor\)。得到暴力式子:\[cnt=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{\lfloo
- 2023-09-1210408 - Farey sequences - UVa
题目要求:给定一个数n,求1—n之间有多少对互质的数,phi【i】数组表示i之前有多少个和i互质的数,a【i】表示前phi【1】+phi【2】+……+phi【i】;a【n】数组就是1---n之间互质的数的对数。。#include<stdio.h>#include<string.h>longlonga[1000010],phi[1000010];longlongn,i,j;i
- 2023-06-14分数相关:Farey Sequence,Stern-Brocot Tree
FareySequence记\(n\)阶FareySequence为\(L_n\),\(L_n\)即为集合\(\{\frac{y}{x}\mid(x,y)=1\land1\leqx\leqn\}\)中的数从小到大写下来,如\(L_5=[\frac01,\frac15,\frac14,\frac13,\frac25,\frac12,\frac35,\frac23,\frac34,\frac45,\frac11]\)。
- 2023-02-07POJ2487 Farey Sequence 欧拉函数模板题
FareySequenceDescriptionTheFareySequenceFnforanyintegernwithn>=2isthesetofirreduciblerationalnumbersa/bwith0<a<b<=nandgcd(a,b)=1
- 2022-11-09POJ 2478 Farey Sequence
DescriptionTheFareySequenceFnforanyintegernwithn>=2isthesetofirreduciblerationalnumbersa/bwith0<a<b<=nandgcd(a,b)=1arrang