FYH666666 @ 2024-04-13 19:39:39
#include<bits/stdc++.h>
using namespace std;
int t;
int main(){
scanf("%d",&t);
while(t-->=0){
t--;
int q[10000];
int jw=0,len=1,a,b;
for(int i=1;i<=10000;i++) q[i]=0;
q[1]=1;
scanf("%d%d",&a,&b);
for(int i=2;i<=a;i++){
jw=0;
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
}
}
// for(int i=len;i>=1;i--) printf("%d",q[i]);
// printf("\n");
long long cnt=0;
for(int i=1;i<=len;i++){
if(q[i]==b) cnt++;
}
printf("%ld\n",cnt);
}
return 0;
}
by queenbee @ 2024-04-13 19:51:33
@FYH666666 虽然但是,你的5!输出为5050000
by queenbee @ 2024-04-13 19:56:46
@FYH666666
#include<bits/stdc++.h>
using namespace std;
int t;
int q[100000];
int main(){
cin>>t;
while(t--){
int jw=0,len=1,a,b;
for(int i=1;i<=100000;i++) q[i]=0;
q[1]=1;
scanf("%d%d",&a,&b);
for(int i=2;i<=a;i++){
jw=0;
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
}
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
}
// for(int i=len;i>=1;i--) printf("%d",q[i]);
// printf("\n");
long long cnt=0;
for(int i=1;i<=len;i++){
if(q[i]==b) cnt++;
}
printf("%ld\n",cnt);
}
return 0;
}
这样阶乘对了,但全WA
by bulopi @ 2024-04-13 19:57:46
@FYH666666 AC代码```cpp
using namespace std;
int t;
int main(){
scanf("%d",&t);
while(t--){
int q[100000];
int jw=0,len=1,a,b;
for(int i=1;i<=100000;i++) q[i]=0;
q[1]=1;
scanf("%d%d",&a,&b);
for(int i=2;i<=a;i++){
jw=0;
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
}
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
}
// for(int i=len;i>=1;i--) printf("%d",q[i]);
// printf("\n");
long long cnt=0;
for(int i=1;i<=len;i++){
if(q[i]==b) cnt++;
}
printf("%ld\n",cnt);
}
return 0;
}
by bulopi @ 2024-04-13 19:58:35
@FYH666666 AC代码
#include<bits/stdc++.h>
using namespace std;
int t;
int main(){
scanf("%d",&t);
while(t--){
int q[100000];
int jw=0,len=1,a,b;
for(int i=1;i<=100000;i++) q[i]=0;
q[1]=1;
scanf("%d%d",&a,&b);
for(int i=2;i<=a;i++){
jw=0;
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
}
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
}
long long cnt=0;
for(int i=1;i<=len;i++){
if(q[i]==b) cnt++;
}
printf("%ld\n",cnt);
}
return 0;
}
by queenbee @ 2024-04-13 20:01:48
@bulopi 为啥q在while里定义才能A?
by bulopi @ 2024-04-13 20:03:57
while(t-->=0){
t--;
…………
}
可改为
while(t--){
…………
}
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
}
可以改为这样:
for(int j=1;j<=len;j++){
q[j]=q[j]*i+jw;
jw=q[j]/10;
q[j]=q[j]%10;
}
while(jw>0){
len++;
q[len]=jw%10;
jw/=10;
}
by queenbee @ 2024-04-13 20:09:11
@bulopi 建议开到100001,虽然我不知道为什么在遍历1~100000是没有超,但是在main外面定义会WA
by FYH666666 @ 2024-04-13 20:34:53
@bulopi 已关感谢啦
by FYH666666 @ 2024-04-13 20:35:26
@queenbee 关注啦谢谢