Title Description
Description
Hzwer really can play ah ... He has a n*m box that can add an entire row or column to a square at a time, but it cannot be deleted. Now he wants to make the total number of squares more than K, but wants to make the total number of squares as small as possible. Please find out the n,m at this time. If there are multiple solutions, output any one.
Enter a description
Input Description
A row of 3 number n,m,k.
Output description
Output Description
The first line is a number ans, which indicates the number of squares at this time.
The second line is two number M ', n ', which indicates the number of rows at this time. If there are multiple solutions, output any one
Sample input
Sample Input
3 5 18
Sample output
Sample Output
18
6 S
Data range and Tips
Data Size & Hint
For 100% data, 1<=m,n<=10^9,1<=k<=10^12.
Test instructions is a given n,m,k, requiring a>=n,b>=m to be found, making a*b>=k and a*b minimal. If there is more than one solution, the output is the smallest dictionary order scheme.
N*m>=k, you can exit directly
otherwise n*m<k
Consider fixing a number A, the other number is k/a. Then you can use (a,k/a) to update the answer.
If you enumerate a, then just go to sqrt (k). Because we enumerate from 1 to a, if there are k/a<a, then certain k/a have been enumerated. There's no point in this state.
So one for to sqrt (k) can
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <algorithm>7#include <ctime>8 #defineLL Long Long9 using namespacestd;Ten LL n,m,k; One BOOLRev; A inline LL read () - { -LL x=0, f=1;CharCh=GetChar (); the while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; - } + intMain () - { +N=read (); M=read (); k=read (); A if(n>m) Swap (n,m), rev=1; at if(n*m>=k) - { -printf"%lld\n%lld%lld"Nm,n,m); - return 0; - } - while(1) in { - BOOLmrk=0; LL a=0; to for(intI=n;i<=sqrt (k); i++) + if(k%i==0&&k/i>=m) - { themrk=1; *A=i; $ Break;Panax Notoginseng } - if(MRK) the { + if(!rev) printf ("%lld\n%lld%lld", k,a,k/a); A Elseprintf"%lld\n%lld%lld", k,k/a,a); the return 0; +}Elsek++; - } $}
codevs4160
2015.9.11 simulator Codevs 4160 "will play"