Factorial Division CSU - 1781

factorial division

 CSU - 1781

Input two positive integers n, m, output n!/m!, where the factorial is defined as n!= 1*2*3*...*n (n>=1). For example, if n=6, m=3, then n!/m!=6!/3!=720/6=120.

Isn't that easy? Now let's reverse the problem: enter k=n!/m! and find such an integer two-tuple (n,m) (n>m>=1).

If the answer is not unique, n should be as small as possible. For example, if k=120, the output should be n=5, m=1, not n=6, m=3, because 5!/1!=6!/3!=120, and 5<6.

Input

The input contains no more than 100 sets of data. Each set of data contains an integer k (1<=k<=10^9).

Output

For each set of data, output two positive integers n and m. No solution outputs "Impossible", and n should be as small as possible when there are multiple solutions.

Sample Input

120
1
210

Sample Output

Case 1: 5 1
Case 2: Impossible
Case 3: 7 4

Hint

 

Wa a lot of hair, the brain is not very good

#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define LL long long
using namespace std;
int main()
{
    LL n;
    int c=0;
    while(scanf("%lld",&n)!=EOF)
    {
        printf("Case %d: ",++c);
        if(n==1)
            printf("Impossible\n");
            else
        if(n&1)
        {
            printf("%lld %lld\n",n,n-1);
        }
        else
        {
            int flag=0;
            //int c=sqrt(n*1.0);
            LL ans1,ans2;
            LL i,j;
            for(i=2;i*i<=n;i++)
            {
                LL temp=i;
                for(j=i+1;;j++)
                {
                    temp*=j;
                    if(temp==n)
                    {
                        flag=1;
                        ans1 = i;
                        ans2=j;
                        break;
                    }
                    if(temp>n)
                        break;
                }
                if(flag)
                    break;
               // printf("%I64d\n",i);
            }
            if(flag)
            {
                printf("%lld %lld\n",ans2,ans1-1);
            }
            else
                printf("%lld %lld\n",n,n-1);
        }
    }
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325162320&siteId=291194637