sleepinmybed @ 2022-07-21 09:07:02
源代码如下:
#include<bits/stdc++.h>
using namespace std;
int o,num[2570];
int main() {
cin >> o;
int n,a;
for (int i=1;i<=o;i++) {
cin >> n >> a;
int tms=0;
memset(num,0,sizeof(num));
for (int j=0;j<floor(log10(n+1)+1);j++) {
num[j]=(n/int(pow(10,j)))%int(pow(10,j+1));
}
for (int j=n-1;j>1;j--) {
for (int k=0;k<2570;k++) {
num[k]*=j;
if (k>0) {
num[k]+=num[k-1]/10;
num[k-1]%=10;
}
}
}
int p;
for (int j=2569;j>=0;j--) {
if (num[j]!=0) {
p=j;
break;
}
}
for (int j=p;j>=0;j--) {
if(num[j]==a) tms++;
}
cout << tms << endl;
}
return 0;
}
求助大佬......
by Hansitory @ 2022-07-21 21:26:01
将第 12 行的代码改为
num[j]=(n%int(pow(10,j+1)))/int(pow(10,j));
即可 AC。可以取一个
另给出一种本人的维护答案位数的做法,抛砖引玉:
int bit = 1; // bit 为答案位数
memset(res, 0, sizeof(res)); // res 数组用来维护答案
res[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < bit; j++) {
res[j] *= i;
}
for (int j = 0; j < bit; j++) {
res[j + 1] += res[j] / 10;
res[j] %= 10;
}
while (res[bit]) {
res[bit + 1] += res[bit] / 10;
res[bit] %= 10;
bit++;
}
}
by sleepinmybed @ 2022-07-22 09:15:17
@Hansests 谢谢钛铌