jyj6222 @ 2024-07-28 15:44:56
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int c[100000],cc[100000],cnt=1;
int main() {
int n;
cin>>n;
while(n--) {
memset(c,0,sizeof c);
c[1]=1;
cnt=1;
int a,s;
cin>>a>>s;
for(int i=1; i<=a; i++) {
memset(cc,0,sizeof cc);
for(int j=1; j<=cnt; j++) {
int ans=0,z=j;
ans=c[j]*i;
while(ans) {
cc[z]+=ans%10;
if(cc[z]>=10) {
cc[z+1]+=cc[z]/10;
cc[z]%=10;
}
ans/=10;
z++;
}
while(cc[z]>=10){
cc[z+1]+=cc[z]/10;
cc[z]%=10;
z++;
}
}
while(cc[cnt+1]){
cnt++;
}
for(int i=1;i<=cnt;i++) c[i]=cc[i];
}
while(c[cnt+1]) cnt++;
// for(int i=cnt; i>=1; i--){
// cout<<c[i];
// }
int t=0;
for(int i=cnt; i>=1; i--){
if(c[i]==s) t++;
}
cout<<t<<endl;
}
return 0;
}
by LHX_18460366315 @ 2024-07-28 21:16:38
@jyj6222 拿我的代码参考一下:
#include<bits/stdc++.h>
using namespace std;
int x[10005],y[10005],ans[10005];
void clear(){ //初始化
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(ans,0,sizeof(ans));
}
string big_date_plus(string s1,string s2){
clear();
int len_a = s1.size(),len_b = s2.size();
int len_c = max(len_a,len_b);
//将s1和s2倒序存储在 x[] 和 y[] 中
for (int i = 0;i < len_a;i++){
x[i] = s1[len_a - 1 - i] - '0';
}
for (int i = 0;i < len_b;i++){
y[i] = s2[len_b - 1 - i] - '0';
}
//计算
int z = 0;
for (int i = 0;i < len_c;i++){
ans[i] = x[i] + y[i] + z;
z = ans[i] / 10;
ans[i] %= 10;
//处理最后的进位
if (z && i == len_c - 1){
len_c++;
}
}
string s3 = "";
//倒序返回
for (int i = len_c - 1;i >= 0;i--){
s3 += ans[i] + '0';
}
return s3;
}
string big_date_multiply(string s1,string s2){
clear();
int len_a = s1.size(),len_b = s2.size();
int len_c = len_a + len_b;
//将s1和s2倒序存储在 x[] 和 y[] 中
for (int i = 0;i < len_a;i++){
x[i] = s1[len_a - 1 - i] - '0';
}
for (int i = 0;i < len_b;i++){
y[i] = s2[len_b - 1 - i] - '0';
}
//计算
for (int i = 0;i < len_a;i++){
int z = 0;
for (int j = 0;j < len_b;j++){
ans[i + j] += x[i] * y[j] + z;
z = ans[i + j] / 10;
ans[i + j] %= 10;
}
ans[i + len_b] = z;
}
string s3 = "";
//判断最高位是否为 0
while (ans[len_c - 1] == 0 && len_c > 1){
len_c--;
}
//倒序返回
for (int i = len_c - 1;i >= 0;i--){
s3 += ans[i] + '0';
}
return s3;
}
int main(){
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
long long t,n,k,cnt = 0;
string res;
cin >> t;
for (int i = 1;i <= t;i++){
cin >> n >> k;
cnt = 0;
res = "1";
for (int j = 1;j <= n;j++){
res = big_date_multiply(res,to_string(j));
}
long long ress = res.size();
for (int j = 0;j < ress;j++){
if (res[j] - '0' == k){
cnt++;
}
}
cout << cnt << endl;
}
return 0;
}
by jyj6222 @ 2024-07-29 08:19:52
@ZZYX_18670145320 你用的高精乘高精吗?
by LHX_18460366315 @ 2024-07-29 09:55:59
@jyj6222 对a
by jyj6222 @ 2024-07-29 10:35:00
@ZZYX_18670145320 好的,谢谢