CF 854A - Fraction
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction? is called proper iff its numerator is smaller than its denominator (a?<?b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (?+?) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction? such that sum of its numerator and denominator equals n. Help Petya deal with this problem.
----------------------------------------------------
Petya 是數(shù)學的忠實粉絲,尤其是與分數(shù)相關的部分。 最近他了解到,如果一個分數(shù)的分子小于分母(a?<?b),則該分數(shù)被稱為真分數(shù);如果其分子和分母互質(除了 1 之外,它們沒有正公約數(shù)),則該分數(shù)被稱為不可約分數(shù)。
在空閑時間,佩蒂亞思考不可約分數(shù)并使用計算器將其轉換為小數(shù)。 有一天,他錯誤地按了加法按鈕(?+?)而不是除法按鈕(÷),得到的分子和分母之和等于n,而不是預期的小數(shù)符號。
彼佳想要恢復原來的分數(shù),但很快他意識到這可能不是唯一的方法。 這就是為什么他決定確定最大可能的真不可約分數(shù),使其分子和分母之和等于 n。 幫助 Petya 解決這個問題。
-----------------------------------------------
依次遍歷即可,主要是要判斷最大公約數(shù)等于1;
下面是代碼: