Display Size CodeForces
来源:互联网 发布:网络助手 红米 编辑:程序博客网 时间:2024/05/22 11:47
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.
题意:给你一个数n,n=a*b;要求a<b并且使a,b的差值最小。
分析:在for循环里定义一个i,使i*i的小于n,这样就和求n开平方根缩小范围一样,其次if条件,里面是给a,b,赋值
这种方法会保证b始终大于a
#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#include <string.h>#define N 100001;using namespace std;int main(){ int n; while(cin>>n) { int a=0,b=0; for(int i=1;i*i<=n;i++) { if(n%i==0) { a=i; b=n/i; } } printf("%d %d\n",a,b); }}
- Display Size CodeForces
- 【codeforces 747A】Display Size
- 【74.00%】【codeforces 747A】Display Size
- Display Size
- Codeforces Round #387(Div. 2)A. Display Size【暴力】
- Codeforces Round #387 (Div. 2)A. Display Size(水题)
- Codeforces Round #387 (Div. 2) 747A Display Size
- Codeforces Round #387 (Div. 2) A. Display Size
- A. Display Size 水题
- 747A Display Size
- A. Display Size
- Android N Display Size
- Android N Display Size
- Codeforces Round #387 (Div. 2)A~D A Display Size D Winter Is Coming
- Codeforces Round #387 (Div. 2)A. Display Size(简单数学)
- CodeForces 416D Population Size
- codeforces 416D Population Size
- 解决Font size和Display size设置到最大,显示异常的问题
- 森林、树、二叉树的相互转换
- 小a和小b一起玩一个游戏,两个人一起抛掷一枚硬币,正面为H,反面为T。两个人把抛到的结果写成一个序列。如果出现HHT则小a获胜,游戏结束。如果HTT出现则小b获胜。问a获胜的概率?
- e.target与e.currentTarget区别
- HttpURLConnection基本工作原理
- MYSQL学习笔记(十)使用子查询
- Display Size CodeForces
- Android版控件2017.7.23最新更新
- iview日期控件,双向绑定日期格式
- 线段树详解
- jsp radio单选控件取值
- SSL协议流程图解(转载+个人记录)
- scala循环
- 我来说说C#中的委托
- java单例模式写法