最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

UP主的第一場(chǎng)競(jìng)賽——CodeForces Round#730(Div2)題目A

2021-07-11 12:36 作者:非知名科技區(qū)UP  | 我要投稿

作為信息競(jìng)賽人,我們需要學(xué)會(huì)完成“作業(yè)”和進(jìn)行“考試”這兩項(xiàng)技能。近期UP主和隊(duì)內(nèi)的某位hxd一起相約遠(yuǎn)翥樓八層教室,開(kāi)展了那位hxd第N次,本UP主(cai gou)的第一次限時(shí)考試。其中有一道數(shù)學(xué)題讓本UP印象深刻,下面請(qǐng)看題。



Welcome to Rockport City!

It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet?a?dollars and Ronnie has bet?b?dollars. But the fans seem to be disappointed. The excitement of the fans is given by?gcd(a,b), where?gcd(x,y)?denotes the?greatest common divisor (GCD)?of integers?x?and?y. To make the race more exciting, you can perform two types of operations:

  1. Increase both?a?and?b?by?1.

  2. Decrease both?a?and?b?by?1. This operation can only be performed if both?aa?and?bb?are greater than?0.

  3. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.

Note that?gcd(x,0)=x?for any?x0.

Input

The first line of input contains a single integer?t?(1%3C%3Dt%3C%3D5*10%5E3) — the number of test cases.

The first and the only line of each test case contains two integers?a?and?b?<10^18(%0A).

Output

For each test case, print a single line containing two integers.

If the fans can get infinite excitement, print?0.

Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.

簡(jiǎn)單解釋一下,張三和李四正在押錢(qián)下賭注,而圍觀群眾獲得的興奮度是張三和李四押錢(qián)數(shù)目的最大公約數(shù)。二人可以一次同時(shí)增加或減少一元的賭注,已知當(dāng)下張三和李四押下的賭資數(shù)額,請(qǐng)你算出他們產(chǎn)生的最大興奮值和產(chǎn)生最大興奮值最少需要進(jìn)行多少次賭注的增減。

如上,提到最大公約數(shù),我想各位必然會(huì)先想到我們之前學(xué)過(guò)的一種快速取余算最大公約數(shù)的方法,但是如果加上了兩人的操作,我們就必須進(jìn)行搜索。而根據(jù)數(shù)據(jù)范圍顯示,進(jìn)行搜索,一定是不能解決問(wèn)題的,而且ACM賽制最大的特點(diǎn)就是一道題不能拿滿分就是零分,所以,采用數(shù)學(xué)方法完成這個(gè)問(wèn)題大概率是唯一的解法。

根據(jù)題目所給的信息,無(wú)論我們?nèi)绾芜M(jìn)行操作,二人賭注數(shù)額的差值是一定的,這也許就是一個(gè)突破口。在UP考試的時(shí)候就利用了這一點(diǎn),而且我可以證明最大公約數(shù)絕對(duì)不會(huì)超過(guò)兩個(gè)輸入數(shù)據(jù)之間差的絕對(duì)值。

為什么?

因?yàn)槿绻环线@個(gè)條件,那么若較小數(shù)再加上一個(gè)公約數(shù)就一定會(huì)大于較大的數(shù),這個(gè)數(shù)就一定不是公約數(shù)了。所以,我可以大致上認(rèn)定輸出的最大興奮值一定是兩個(gè)數(shù)的差的絕對(duì)值。

那么將較小的數(shù)作為0和大數(shù)的中點(diǎn)豈不是就可以了?然后我們也就能夠得到最少所需的操作次數(shù)。

其實(shí)這樣也不是一個(gè)正確的選擇,對(duì)于這一點(diǎn)我們可以參看一下樣例輸入中的第一條數(shù)據(jù),仔細(xì)研究你就會(huì)發(fā)現(xiàn),我們要找的本質(zhì)上是較小的輸入值和大小輸入值差的整倍數(shù)的最小距離,如此一來(lái)就能夠得到正確的解了。

文章的最后,放出AC代碼


UP主的第一場(chǎng)競(jìng)賽——CodeForces Round#730(Div2)題目A的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
西安市| 台北县| 略阳县| 迭部县| 曲麻莱县| 集贤县| 原平市| 赤峰市| 阜新市| 滁州市| 呈贡县| 通许县| 静乐县| 苍梧县| 新龙县| 太白县| 拜泉县| 醴陵市| 梅河口市| 新乡市| 长海县| 太谷县| 苏尼特右旗| 定日县| 新密市| 竹北市| 镇康县| 汶川县| 闵行区| 凤山县| 南木林县| 喀喇| 车险| 郴州市| 新巴尔虎右旗| 娄底市| 阜新| 吴堡县| 长岛县| 类乌齐县| 玉门市|