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 ;
}
Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A的更多相关文章
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...
- Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937
https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...
- 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...
- 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...
- Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...
随机推荐
- BZOJ 1724 [Usaco2006 Nov]Fence Repair 切割木板:贪心 优先队列【合并果子】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1724 题意: 你要将一块长木板切成n段,长度分别为a[i](长木板的长度 = ∑ a[i] ...
- IntelliJ IDEA 中详细图解记录如何连接MySQL数据库
- springmvc的简单介绍以及springmvc组件的介绍
Spring web mvc框架 什么是springmvc Springmvc是spring框架的一个模块,spring和springmvc无需中间整合层整合 Springmvc是一个基于mvc的we ...
- loading bar
上面的loading条,想到的办法是用两个半圆覆盖实现,结果也就这么做了,可是明明一个圆就可以的,哎智商堪忧... <!DOCTYPE html> <html lang=" ...
- GIT的Push和Pull,强制Pull覆盖本地命令
连接命令: git remote add origin + 你Git库的地址 其中,origin是你对这个Git库地址的标识. 一. 把文件从本地上传到库中 第一步:使用命令 git add命令把文件 ...
- CentOS 性能监控之nmon
工具集: Nmon 性能数据收集分析工具Nmon analyser 性能数据分析工具,excel文件nmon_x86_sles10 Nmon在x86_sles10下二进制执行文件 nmon概述 n ...
- Cloudera Manager 5 和 CDH5 本地(离线)安装指南
http://archive.cloudera.com/cm5/redhat/6/x86_64/cm/5.0.0/RPMS/x86_64/ http://archive-primary.clouder ...
- terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr
运行时报错: terminate called after throwing an instance of 'std::out_of_range'what(): basic_string::subs ...
- AtCoder Regular Contest 072 E:Alice in linear land
题目传送门:https://arc072.contest.atcoder.jp/tasks/arc072_c 题目翻译 给你一个数组\(D\),然后给你一个操作序列\(d\),每次操作可以将\(D\) ...
- jdbc代码
1.jdbcutiul的代码, package gz.itcast.util; import java.io.InputStream; import java.sql.Connection; impo ...