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& ...
随机推荐
- gVIM+zencoding快速开发HTML/CSS/JS(适用WEB前端)
一.真正解决了UTF-8中文乱码的各种问题(菜单乱码,内容乱码,提示信息乱码),不用担心WIN用默认编码写的东西在Linux乱码,或在Linux(zh_CN.UTF-8时)写的东西在WIN下乱码.在A ...
- python-多线程2-线程同步
线程同步: 一个场景: 一个列表里所有元素都是0,线程A从后向前把所有元素改成1,而线程B负责从前往后读取列表并打印. 那么,可能线程A开始改的时候,线程B便来打印列表了,输出就变成一半0一半1,这就 ...
- leetcode 66. Plus One(高精度加法)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- Android Studio的技巧
1.快速添加add unimplements methods: 右键generate 2.快速添加try-catch:左边就有一个小电灯,然后可以选. 3.格式化OPTION + CMD + L ( ...
- java面试题04
1.就你所熟悉的银行业务面说一下,越详细越好 银行经验:手机银行 网上银行经验 怎么支付 转账 了解基本业务 2.了解工作流的控制,审批流程以及帐务处理么? java中怎么实现工作流.审批流程 ...
- MySql 官方存储引擎
存储引擎是为不同的表类型处理 SQL 操作的 MySql 组件.InnoDB 是默认的.最通用的存储引擎,也是官方推荐使用的存储引擎,除非一些特定案例.MySql 5.6 中的 CREATE TABL ...
- bzoj 5093 图的价值 —— 第二类斯特林数+NTT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5093 每个点都是等价的,从点的贡献来看,得到式子: \( ans = n * \sum\li ...
- node.js setup wizard ended prematurely Win7安装nodejs失败解决方法
笔记本win7在nodejs官方网站下载.msi文件安装,安装到一半的时候,进度条提示:roll back,because of a error.node.JS setup wizard ended ...
- ceph安装对象网关
1.概述 安装3个网关节点分别是:controller-03.controller-04和controller-05,使用ceph gw自带的Civetweb提供服务,前端使用nginx作为前端代理. ...
- 【236】◀▶IEW-Unit01
Unit 1 Fast Food I.动名词的用法 Doing(V-ing) 核心思想:词性是名词,作用是动词 1. 名词 3)主语(句首) 保护环境是我们每个人的责任. Protecting th ...