码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

时间:2017-09-07 13:24:43      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:pos   output   iso   osi   ecif   min   ret   specific   button   

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.

 

Input

In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.

Output

Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.

Examples
input
3
output
1 2
input
4
output
1 3
input
12
output
5 7
题意:a/b 有gcd(a,b)==1 a<b 现在已知a+b=n,我们求最大的a,b
解法:暴力
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int n;
 5     int b,a;
 6     cin>>n;
 7     for(int i=1;i<=n;i++){
 8         for(int j=i+1;j<=n;j++){
 9             if(i+j==n&&__gcd(i,j)==1){
10                 a=i;
11                 b=j;
12             }
13         }
14     }
15     cout<<a<<" "<<b<<endl;
16     return 0;
17 }

 

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

标签:pos   output   iso   osi   ecif   min   ret   specific   button   

原文地址:http://www.cnblogs.com/yinghualuowu/p/7488984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!