K. 爱之核心AI (CI翻译)(GPT 5.6 Terra)
题目描述
Mr. Potato Head works on Unified Non-linear Algorithms about Love (UNAL). These algorithms are connected to a traditional machine learning branch called Kernel methods. Mr. Potato Head has discovered a Kernel function which measures the similarity of two persons and hence can predict the likelihood of them being a good couple. He has taken his discoveries one step forward, after running a Kernel algorithm over a vast database of Facebook profiles, he made some interesting (albeit scary) discoveries: every single human can be mapped bijectively to a Fibonacci number, which allowed him to derive a formula that tells if a couple will be happy for ever and ever.
土豆头先生从事关于爱情的统一非线性算法(Unified Non-linear Algorithms about Love,UNAL)的研究。这些算法与一个名为核方法(Kernel methods)的传统机器学习分支有关。土豆头先生发现了一个核函数,可以衡量两个人之间的相似度,从而预测他们成为般配伴侣的可能性。在此基础上,他又向前迈进了一步:在一个庞大的 Facebook 个人资料数据库上运行核算法后,他得出了一些有趣(尽管有些可怕)的结论:每一个人都可以与一个斐波那契数建立双射关系,这使他得以推导出一个公式,用来判断一对情侣是否会永远幸福。AI (CI翻译)(GPT 5.6 Terra)
The Fibonacci numbers are the sequence of numbers $\{F_k\}_{k=1}^\infty$ defined by the linear recurrence equation $$F_{k+2} = F_{k+1} + F_{k}$$ with $F_1 = F_2 = 1$.
斐波那契数列是由线性递推方程 $$F_{k+2} = F_{k+1} + F_{k}$$ 和 $F_1 = F_2 = 1$ 定义的数列 $\{F_k\}_{k=1}^\infty$。AI (CI翻译)(GPT 5.6 Terra)
A perfect couple is represented by two numbers $x$ and $y$ such that:
完美搭档由两个数 $x$ 和 $y$ 表示,满足:AI (CI翻译)(GPT 5.6 Terra)
$x$ and $y$ are Fibonacci numbers.
$x$ 和 $y$ 是斐波那契数。AI (CI翻译)(GPT 5.6 Terra)
They are attractive to each other but not too much, this holds true when $gcd(x,y) = 1$
它们彼此相互吸引,但吸引力并不太强;当 $gcd(x,y) = 1$ 时,这一点成立。AI (CI翻译)(GPT 5.6 Terra)
They are not too different or too similar, this is achieved when $(x + y) \mod{2} = 1$
它们既不会太不同,也不会太相似,这在 $(x + y) \mod{2} = 1$ 时得以实现。AI (CI翻译)(GPT 5.6 Terra)
Their eternal combination leads to another human being, this means, another Fibonacci number. This happens when $x + y = z$ where $z$ is a Fibonacci number.
它们永恒的结合会产生另一个人类,也就是说,另一个斐波那契数。当 $x + y = z$ 时,这种情况就会发生,其中 $z$ 是一个斐波那契数。AI (CI翻译)(GPT 5.6 Terra)
Mr. Potato Head is astonished with his discovery, he now wants to understand how many truly happy couples are there in the world. For a given $n$ he wants to know how many couples exist on the first $n$ human beings (i.e. the first $n$ Fibonacci numbers) such that all conditions above hold true.
Mr. Potato Head 对自己的发现感到震惊,现在他想了解世界上有多少对真正幸福的情侣。给定 $n$,他想知道在前 $n$ 个人类(即前 $n$ 个斐波那契数)中,满足上述所有条件的情侣共有多少对。AI (CI翻译)(GPT 5.6 Terra)
输入格式
The first line of the input represents the number of test cases. Each case consists of a single integer $n$ $(1 \leq n \leq 10^5)$ per line.
输入的第一行表示测试用例的数量。每个测试用例由每行一个整数 $n$ $(1 \leq n \leq 10^5)$ 组成。AI (CI翻译)(GPT 5.6 Terra)
输出格式
For each case print the number of perfect couples.
对于每组测试用例,输出完美情侣的数量。AI (CI翻译)(GPT 5.6 Terra)
样例
样例 1
6
1
4
8
17
20
250
3
5
11
13
17C. 湖畔漫步AI (CI翻译)(GPT 5.6 Terra)
题目描述
The city of Porto will host the ICPC World Finals in 2019. One of the secret touristic spots in the city is the so-called "lake of the thousand bridges". Mr. Manoel Pontes (Pontes stands for "bridges" in Portuguese; this is amazingly his real name$\ldots$) built this wonder in the lake with a lifetime of hard work. The lake has many small islands. Mr. Manoel built small wooden bridges connecting the islands. In some cases, there are multiple bridges connecting some pairs of islands. Visitors enjoy themselves while promenading through the bridges and small islands. Besides, by walking through the bridges the visitors can go from one island to any other island.
波尔图市将于 2019 年举办 ICPC 世界总决赛。这座城市有一个秘密的旅游景点,被称为“千桥湖”。Manoel Pontes 先生(Pontes 在葡萄牙语中意为“桥”;令人惊讶的是,这确实是他的真名$\ldots$)用毕生的辛劳在湖中建造了这一奇观。湖中有许多小岛。Manoel 先生修建了连接这些岛屿的小木桥。在某些情况下,某些岛屿对之间可能有多座桥相连。游客们喜欢漫步于桥梁和小岛之间。此外,游客可以通过走过桥梁从任意一个岛到达其他任意一个岛。AI (CI翻译)(GPT 5.6 Terra)
Mr. Manoel wants to enhance this touristic attraction to get even more visitors. One of this ideas is to organize visitors games. He plans to have the following challenge: is it possible to start to walk from outside the lake, pass through all the bridges without repetition, and go back to the starting point (that is, back out of the lake)?
曼努埃尔先生希望改进这个旅游景点,以吸引更多游客。他的想法之一是组织供游客参与的游戏。他计划设置如下挑战:能否从湖外出发,经过所有的桥且不重复经过任何一座桥,最后回到出发点(也就是再次走出湖泊)?AI (CI翻译)(GPT 5.6 Terra)
Before creating the attraction, he himself tried it over and over but could not find out if this was possible. To make the challenge even more interesting, Mr. Manoel will allow adding some bridges between some islands. He wants to know if, by adding some of these bridges, the walk he wants the game to have becomes possible. Your task in this problem is to decide if it is possible to choose some (possibly none) of these bridges that, when added, allow people to walk as described.
在创建这个游乐项目之前,他亲自反复尝试,却始终无法确定这是否可行。为了让挑战更加有趣,Manoel 先生允许在一些岛屿之间增建桥梁。他想知道,通过增建其中一些桥梁,是否能使他希望游戏具备的行走方式成为可能。
你的任务是判断:是否可以选择其中一些桥梁(也可以一座都不选)进行增建,使人们能够按照描述的方式行走。AI (CI翻译)(GPT 5.6 Terra)
输入格式
The first line has three integers $N$, $M$ and $K$, where $N$ is the number of islands, $M$ is the number of already built bridges and $K$ is the number of bridges that is possible to add. The islands are represented by distinct integers from $1$ to $N$. Each one of the following $M+K$ lines describes a bridge. Each one of them has two integers, $a$ and $b$, that represent the existence or possibility of adding a bridge between islands $a$ and $b$. The first $M$ lines describe bridges that already exist and the next $K$ lines describe bridges that you may add.
第一行包含三个整数 $N$、$M$ 和 $K$,其中 $N$ 表示岛屿的数量,$M$ 表示已经建成的桥梁数量,$K$ 表示可以新增的桥梁数量。岛屿用从 $1$ 到 $N$ 的互不相同的整数表示。接下来的 $M+K$ 行中的每一行描述一座桥梁。每行包含两个整数 $a$ 和 $b$,表示岛屿 $a$ 和 $b$ 之间是否存在桥梁或是否可以新增桥梁。前 $M$ 行描述已经存在的桥梁,接下来的 $K$ 行描述可以新增的桥梁。AI (CI翻译)(GPT 5.6 Terra)
Constraints
约束条件AI (CI翻译)(GPT 5.6 Terra)
$1 \leq N \leq 3 \cdot 10^5$
$1 \leq N \leq 3 \cdot 10^5$AI (CI翻译)(GPT 5.6 Terra)
$0 \leq M, K \leq 3 \cdot 10^5$
$0 \leq M, K \leq 3 \cdot 10^5$AI (CI翻译)(GPT 5.6 Terra)
$1 \leq a \lt b \leq N$
$1 \leq a \lt b \leq N$AI (CI翻译)(GPT 5.6 Terra)
You may assume that we can go from one island to any other island by using only the bridges already built.
你可以假设,仅使用已经建成的桥,就能从任意一个岛屿到达其他任意岛屿。AI (CI翻译)(GPT 5.6 Terra)
输出格式
In the first line print "YES" (without the quotes), if such a walk is possible or "NO" otherwise. If there is a solution, print in the second line an integer $R$, $0 \leq R \leq K$ that is the number of bridges that need to be added. Next print $R$ lines, each one with two integers, the islands that are connected by this bridge, in any order. If there are multiple solutions, any one will be accepted.
第一行输出“YES”(不含引号),如果可以完成这样的行走;否则输出“NO”。如果存在解决方案,第二行输出一个整数 $R$、$0 \leq R \leq K$,表示需要添加的桥的数量。接下来输出 $R$ 行,每行包含两个整数,表示由这座桥连接的两个岛屿,顺序任意。如果有多个解决方案,输出其中任意一个即可。AI (CI翻译)(GPT 5.6 Terra)
样例
样例 1
4 3 4
1 2
2 3
3 4
1 4
1 4
1 3
3 4YES
1
1 4样例 2
4 3 2
1 2
2 3
3 4
1 2
3 4NO