Codeforces Round #433 Div. 2 A. Fraction
来源:互联网 发布:fluent分析软件 编辑:程序博客网 时间:2024/06/16 06:02
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 ninstead 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.
In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
#include<iostream>#include<cstdio>using namespace std;int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){int n,ans=1,j;scanf("%d",&n);for(int i = 1;i<n;i++){j=n-i;if(i>=j)break;if(gcd(i,j)==1) ans = i;}printf("%d %d\n",ans,n-ans);return 0;}
- Codeforces Round #433 (Div. 2)A. Fraction
- Codeforces Round #433 (Div. 2) A. Fraction
- Codeforces Round #433 Div. 2 A. Fraction
- Codeforces Round #433 (Div. 2) A.Fraction(暴力)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction
- Codeforces Round #433 (Div. 2)A&B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- ccf-火车购票
- 性能测试知多少---响应时间
- python 数据结构 元组、列表、字典、序列
- JS作用域
- java实现二分查找
- Codeforces Round #433 Div. 2 A. Fraction
- 远程调试ambari-metrics的方法
- Java标识符小陷阱
- 广义线性模型与指数分布族
- tomcat能正常启动,但是http://localhost:8080/网页就是打不开,报404
- Linux Ubuntu 使用play命令播放音乐 mp3 wav 等文件
- 《python编程快速上手》学习笔记-----口令保管箱
- secureCRT-多个终端上同时执行同个命令
- leetcode 139. Word Break DP + DFS按照index递归搜索