MC_dream_tsr @ 2024-08-31 13:47:48
全wa,不要AC代码和以P开头的语言,求改,谢谢
# include<bits/stdc++.h>
using namespace std;
const int kk = 3000;
int a1[kk], n[1005], a[1005];
void a1_0() {
for(int i = 0; i < 3000; i++) a1[i] = 0;
}
int jc(int x) {
int ans = 0, len = 1;
for(int i = 2; i <= n[x]; i++)
for(int j = 0; j < len; j++)
a1[j] *= i;
for(int i = 0; i < len; i++){
a1[i + 1] += a1[i] / 10, a1[i] %= 10;
if(a1[len]) len++;
}
for(int i = len - 1; i >= 0; i--)
if(a1[i] == a[x]) ans++;
a1_0();
return ans;
}
int main(){
int t;
cin >> t;
for(int i = 1; i <= t; i++) cin >> n[i] >> a[i];
for(int i = 1; i <= t; i++) cout << jc(i) << endl;
return 0;
}
by Yxy7952 @ 2024-08-31 14:28:24
@MC_dream_tsr
你在往上滑,看看上面的输出,早就爆了
输出证明了一切
by MC_dream_tsr @ 2024-08-31 14:46:17
@yixingyou 谢谢大佬,懂了,调过啦!(把代码多分成几个函数,就过了(好吧,高精阶乘那确实有大问题
by Yxy7952 @ 2024-08-31 14:47:44
@MC_dream_tsr
那能关注吗(跪求)orz
by MC_dream_tsr @ 2024-08-31 14:50:22
@yixingyou 那必须的,被这道橙题卡了好几天
by MC_dream_tsr @ 2024-08-31 14:52:46
%%%%%%
by hehe_666 @ 2024-09-15 09:19:21
@MC_dream_tsr 1000!不止1005位,存不下
#include <bits/stdc++.h>
using namespace std;
int n, a, cnt;
int mul[1000005];
void printBIG(int x[])
{
for(int i = x[0]; i >= 1; i--) cout << x[i];
}
void mulBIG(int x[], int y, int z[])
{
z[0] = x[0];
for(int i = 1; i <= z[0]; i++) z[i] = x[i] * y;
for(int i = 1; i <= z[0]; i++)
{
z[i + 1] += z[i] / 10;
z[i] %= 10;
if(z[z[0] + 1] > 0) z[0]++;
}
}
int main()
{
cin >> n >> a;
mul[0] = mul[1] = 1;
for(int i = 1; i <= n; i++) mulBIG(mul, i, mul);
for(int i = mul[0]; i >= 1; i--)
{
if(mul[i] == a) cnt++;
}
cout << cnt;
return 0;
}