admin管理员组文章数量:1558098
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.
InputIn the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.
OutputOutput two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Example Input3Output
1 2Input
4Output
1 3Input
12Output
5 7
题意:给一个数,把它拆成最大的分子分母互质的真分数形式。
#include<stdio.h>
int gcd(int p,int q)
{
return q==0? p:gcd(q,p%q);
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=n>>1;i>=1;i--)
{
if(gcd(i,n-i)==1)
{
printf("%d %d\n",i,n-i);
break;
}
}
return 0;
}
本文标签: 水题
版权声明:本文标题:水题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726363677a1067182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论