【codeforces 747A】Display Size
来源:互联网 发布:淘宝举证是什么意思 编辑:程序博客网 时间:2024/06/06 12:42
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:
- there are exactly n pixels on the display;
- the number of rows does not exceed the number of columns, it means a ≤ b;
- the difference b - a is as small as possible.
The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.
Print two integers — the number of rows and columns on the display.
8
2 4
64
8 8
5
1 5
999999
999 1001
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
同样的贪心,开平方之后从大到小找第一个解,math函数库里的sqrt函数的参数不能放int不然会CE,重载调用的问题,可以强转
AC代码:
#include<iostream>#include<algorithm>#include<math.h>#include<cstring>using namespace std;int main(){ double m; while(cin>>m) { int a, b; double y = sqrt(m); int x = (int)y; int n = int(m); if(n % x == 0) { a = x; b = n / x; } else { while(n % x != 0) { x--; } a = x; b = n / x; } cout<<a<<" "<<b<<endl; } return 0;}
- 【codeforces 747A】Display Size
- 【74.00%】【codeforces 747A】Display Size
- 747A Display Size
- Codeforces Round #387 (Div. 2) 747A Display Size
- Display Size CodeForces
- Codeforces Round #387(Div. 2)A. Display Size【暴力】
- Codeforces Round #387 (Div. 2)A. Display Size(水题)
- Codeforces Round #387 (Div. 2) A. Display Size
- A. Display Size 水题
- A. Display Size
- Codeforces Round #387 (Div. 2)A~D A Display Size D Winter Is Coming
- Codeforces Round #387 (Div. 2)A. Display Size(简单数学)
- Display Size
- Android N Display Size
- Android N Display Size
- CodeForces-747A
- CodeForces - 747A
- size(A,1)
- (1) near "limit": syntax error (sqlite报错)
- 从编译角度看java域和方法
- 循环链表c语言实现 circlelinklist.h 和 circlelinklist.c
- 火车出站
- 循环从终端输入整数,在循环体中求出奇数的个数以及偶数的个数,当输入值为0时循环退出
- 【codeforces 747A】Display Size
- 浅谈ARP协议
- JVM处理兼容具体措施的分析
- Qt 多线程之间的通信 实例 emit
- 计算二进制数中1的个数
- python之decode、encode及codecs模块
- Centos7安装mysql
- Linux安装,连接,删除FTP服务器(常用FTP命令)
- (水仙花数问题)假设100