阶乘除法

输入两个正整数 n, m,输出 n!/m!,其中阶乘定义为 n!= 1*2*3*...*n (n>=1)。 比如,若 n=6, m=3,则n!/m!=6!/3!=720/6=120

是不是很简单?现在让我们把问题反过来:输入 k=n!/m!,找到这样的整数二元组(n,m) (n>m>=1)

如果答案不唯一,应该尽量小。比如,若 k=120,输出应该是 n=5m=1,而不是 n=6m=3,因为5!/1!=6!/3!=120,而 5<6

Input

输入包含不超过 100 组数据。每组数据包含一个整数 k (1<=k<=10^9)。

Output

对于每组数据,输出两个正整数 n 和 m。无解输出"Impossible",多解时应让 n 尽量小。

Sample Input
120
1
210
Sample Output
Case 1: 5 1
Case 2: Impossible
Case 3: 7 4
 
 
暴力做出来的。
 
 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int m,i,j,k,t;
    k=1;
    long long n,sta,en;
    while(scanf("%lld",&n)!=EOF)
    {
        int f=0;
        printf("Case %d: ",k);
        k++;
        if(n==1)
        {
            printf("Impossible\n");
            continue;
        }
        for(i=2; i*i<=n; i++)
        {
            long long t=i;

            for(j=i+1;; j++)
            {
                //printf("%d\n",t);
                t=t*j;
                if(t==n)
                {
                    f=1;
                    sta=j;
                    en=i;
                    break;
                }
                if(t>n)
                    break;
            }
            if(f==1)
                break;
            //printf("%d\n",t);

        }
        if(f==1)
        printf("%lld %lld\n",sta,en-1);
        else
        {
            printf("%lld %lld\n",n,n-1);
        }
    }
    return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值