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.
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.

Example
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.

题意:给你一个数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);    }}