QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196217#6956. Many Topological Problemsyiyiyi#AC ✓49ms3636kbC++14687b2023-10-01 14:12:442023-10-01 14:12:44

Judging History

你现在查看的是最新测评结果

  • [2023-10-01 14:12:44]
  • 评测
  • 测评结果:AC
  • 用时:49ms
  • 内存:3636kb
  • [2023-10-01 14:12:44]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define re register
#define N 1020030
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int mo=1000000007;
inline int read(){
	int x=0,w=0;char ch=getchar();
	while (!isdigit(ch))w|=ch=='-',ch=getchar();
	while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return w?-x:x;
}

void solve(){
	int n=read(),k=read(),ans=1;
	if (n==k)--k;
	for (int i=1;i<=k;++i)ans=ans*i%mo;
	for (int i=1;i<=n;++i)ans=ans*i%mo;
	for (int i=1;i<=n-k-1;++i)ans=ans*k%mo;
	cout<<ans<<endl;		
}
signed main(){
    int T=read();
    while (T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 49ms
memory: 3636kb

input:

10
1 1
700503 623646
939811 584922
752155 569391
348265 116258
839298 839298
800391 216447
150847 116426
370812 168588
1000000 407619

output:

1
972550684
617838838
561525568
470024873
910196299
782371500
133886363
868118624
262962652

result:

ok 10 lines