Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A
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.
3
1 2
4
1 3
12
5 7
题意:a/b 有gcd(a,b)==1 a<b 现在已知a+b=n,我们求最大的a,b
解法:暴力
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int b,a;
cin>>n;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(i+j==n&&__gcd(i,j)==){
a=i;
b=j;
}
}
}
cout<<a<<" "<<b<<endl;
return ;
}
最新文章
- JS date常用代码积累
- java线程内存模型,线程、工作内存、主内存
- Jmeter在linux上运行(命令行运行Jmeter)
- Qt消息机制和事件(一)
- CentOS学习笔记&mdash;软件管理程序RPM、YUM
- sqlite使用小结
- Python下调用Linux的Shell命令
- nginx+apache+php+mysql服务器集群搭建
- Java中的break与continue区别
- 浅谈C51内存优化
- 关于Set Nocount ON的性能 |c#调用存储过程的返回值总是-1
- 将Datagridview中的数据导出至Excel中
- 切割模型固定写死了切平面方程是y=0.1
- window.jQuery || document...
- java.net.UnknownHostException: www.terracotta.org
- linux 压缩命令
- How to Change MAC Address on Ubuntu
- SpringMVC中的 JSR 303 数据校验框架说明
- nginx 限流配置
- 如何看待阿里 AI 每秒制作 8000 张海报?
热门文章
- cmake编译后vs编译(build Solution)报错的解决办法
- 农业公司flash动画模板
- (转)C/C++——auto,static,register,extern用法
- poj 3415 Common Substrings —— 后缀数组+单调栈
- 普通项目转为maven项目及相关操作说明
- requests.session保持会话
- jquery/原生js/css3 实现瀑布流以及下拉底部加载
- 如何增加新的PointT类型
- Uncommon Words from Two Sentences
- day1 java基础回顾-Junit单元测试