【74.00%】【codeforces 747A】Display Size
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.
Output
Print two integers — the number of rows and columns on the display.
Examples
input
8
output
2 4
input
64
output
8 8
input
5
output
1 5
input
999999
output
999 1001
Note
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.
【题目链接】:http://codeforces.com/contest/747/problem/A
【题解】
暴力枚举n的因子x
看看n/x是不是满足x<=n/x
然后记录那个差最小的就好.
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int n;
int ma = 1e7,ansa,ansb;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
if ((n%i)==0)
{
int a = n/i;
int b = i;
if (a <= b)
{
if (b-a<=ma)
{
ma = b-a;
ansa = a;
ansb = b;
}
}
}
cout << ansa<<" "<<ansb<<endl;
return 0;
}
【74.00%】【codeforces 747A】Display Size的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【50.00%】【codeforces 602C】The Two Routes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.00%】【codeforces 584E】Anton and Ira
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【50.00%】【codeforces 747C】Servers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 757D】Felicity's Big Secret Revealed
[题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
随机推荐
- 【JZOJ3824】【NOIP2014模拟9.9】渴
SLAF 世界干涸,Zyh认为这个世界的人们离不开水,于是身为神的他要将他掌控的仅仅两个水源地放置在某两个不同的城市.这个世界的城市因为荒芜,他们仅仅保留了必要的道路,也就是说对于任意两个城市有且仅有 ...
- 【JZOJ4899】【NOIP2016提高A组集训第17场11.16】雪之国度
题目描述 雪之国度有N座城市,依次编号为1到N,又有M条道路连接了其中的城市,每一条道路都连接了不同的2个城市,任何两座不同的城市之间可能不止一条道路.雪之女王赋予了每一座城市不同的能量,其中第i座城 ...
- springboot security 安全
spring security几个概念 “认证”(Authentication) 是建立一个他声明的主体的过程(一个“主体”一般是指用户,设备或一些可以在你的应用程序中执行动作的其他系统) . “授权 ...
- matlab 单元最短路 Dijkstra算法 无向图
W = [2 8 1 1 6 5 1 2 3 6 4 9 3 7 9]; S = [0 0 0 1 1 3 3 3 5 5 6 4 6 2 2];S=S+1; T = [1 3 2 4 3 4 5 6 ...
- Cmake在编译osgEarth时遇到的一个错误
CMake Error at src/osgEarthDrivers/CMakeLists.txt:7 (PROJECT): The CMAKE_C_COMPILER: llvm-gcc-4.2 is ...
- 项目上使用的每月1日自动导出Zabbix性能数据的python脚本
基于zabbix-manager python2.7 #!/usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "life&q ...
- Java练习 SDUT-2561_九九乘法表
九九乘法表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题 ...
- 原生js复习1.0
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- ArcGIS 如何设置地图显示范围大小
说来惭愧,学ArcGIS也已经有两年了.今天才知道原来ArcGIS是可以设置地图显示范围大小的 打开ArcMap,选择左边图例的图层(Layers) ,右键点击,选择属性(Properties..), ...
- 2019-3-25-win10-uwp-如何将像素数组转-png-文件
title author date CreateTime categories win10 uwp 如何将像素数组转 png 文件 lindexi 2019-3-25 8:53:1 +0800 201 ...