Description
输入两个正整数 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)。
如果答案不唯一,n 应该尽量小。比如,若 k=120,输出应该是 n=5, m=1,而不是 n=6, m=3,因为 5!/1!=6!/3!=120,而 5<6。
Input
Output
Sample Input
120 1 210
Sample Output
Case 1: 5 1 Case 2: Impossible Case 3: 7 4
Hint
无
一开始写搓了 暴力T了一发 以为不可以 结果就是暴力....
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int,int> PII;LL k;
LL ans1;
LL ans2;int main()
{//FINint cas = 1;while(~scanf("%I64d", &k)){if(k == 1){printf("Case %d: Impossible\n", cas++);continue;}LL i, j;int flag = 0;for(i = 2;i*i <= k; i++) {LL p = i;for(j = i+1;; j++) {p *= j;if(p == k) {flag = 1;ans1 = j;ans2 = i;break;}if(p > k)break;}if(flag)break;}if(flag) printf("Case %d: %I64d %I64d\n", cas++, ans1, ans2-1);else printf("Case %d: %I64d %I64d\n", cas++, k, k-1);}return 0;}