Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

7231. Homework

Problem code: HOMEW

When trying to clean your old room, you find out your old notes from high school.
Reading the homeworks you were given then, you start thinking how much easier they
would have been today. However, there is a particular one that still seems to maintain
its difficulty.

When the solution to a problem involved solving the square root of an integer, to keep
a fancy and clean expression, you were asked to express it as the integer part and the
root part. This means that if you had as solution N you were asked to express it
as √N = A √B with the part A being as high as possible. For instance, 180 can be
expressed as 1 √180, 2 √45, 3 √20 or 6 √5. Of course, the last expression is the correct
one.

Now that you are grown up, you decide to write a program to perform this task for you.

Input

The input contains several test cases, each one described in a single line. The line contains
an integer N (1 ≤ N ≤ 1018 ). The last line of the input contains a single −1 and should
not be processed as a test case.

Output

For each test case output a single line with two integers A and B separated by a single
space such that √N = A √B and A is maximum.

Example

Input:
180
17
1000000000000000000
-1

Output: 6 5
1 17
1000000000 1

Added by:Pablo Ariel Heiber
Date:2010-08-24
Time limit:400s
Source limit:50000B
Languages:All except: PERL 6
Resource:FCEyN UBA ICPC Selection 2009

hide comments
2012-01-31 11:12:34 Forsad Al Hossain
@Author
Why the time limit is increased ? With the number of test cases in the current dataset it is possible to solve this problem within 7-8 seconds.
2011-07-16 19:37:32 sandeep pandey
No of Test case??
2010-09-03 21:03:06 Agustin Santiago Gutierrez
It is not necesary to fully factorize the number to solve the problem.
2010-09-01 02:28:13 kawmia institutes problem setters
time must be increased
my solution finished in 1min , 22 sec so why is it tle

Last edit: 2010-08-25 18:32:44
2010-09-01 02:28:13 Ravi Kiran
@Problem Setter
Why did my solution show Accepted and then TLE after i refreshed the page.It showed a runtime of ~95 secs.
Maybe you should consider easing the time limit by 20 secs to allow my pollard rho in python to pass.

Last edit: 2010-08-25 15:43:26
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.