水题
水题
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;
}
- 笔记本电脑显示屏“坏点”的识别
- 什么是Wi-Fi?
- 如何一键重装系统环境
- mac 查看日志less用法
- U盘恢复方法
- 15个版本Windows XP 高速下载
- Win7 安装 VisualStudio2019
- d3d12.dll丢失怎么修复-d3d12.dll修复工具下载
- 计算机开机后黑屏鼠标显示桌面图标,电脑开机后黑屏只有一个鼠标箭头怎么办 电脑黑屏的解决方法...
- wifi显示但是没有网络连接到服务器是怎么回事,wifi连接后显示网络连接不可用怎么办?...
- H3C ER3260G2路由器提示网络连接总数已经达到限制
- 小米路由器同一wifi局域网下,各主机无法ping连
- 安装debian11系统
- 【系统之家首发】11月最新系统GHOSTXP_SP3电脑公司快速装机版V2011.11
- 戴尔微型计算机重装WIN10系统,戴尔品牌机如何重装win10系统
- Keil(MDK-ARM)介绍、下载、安装与注册
- 无线网怎么调成一个服务器,两个无线路由器怎么设置到一个局域网内?