| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 3744 | Accepted: 1952 |
Description
There is just one basic rule in the Idiot of the Year Contest (IYC)! The contestant picks a random digit between 0 and 9, computes the factorial of the day of the year he/she is born, and counts the how many times the digit picked appears in the factorial. The contestant with highest count is the Idiot of the Year! For example, if you are born on 5th of Mordad which is the 129th day of the year, and you pick the digit 6, your score will be the number of times the digit 6 appears in 129! (that is 1 × 2 × 3 × ... × 129).
The chief judge of IYC wants you to write a program to get an integer which is the day of the year a contestant is born on and a digit and report the number of times the digit appears in the factorial of the first number.
Input
The first line of the input contains a single integer T which is the number of test cases, followed by T lines each containing the data for a test case having two numbers. The first number is the day of the year a contestant is born and the second one is the digit he/she has picked.
Output
The output contains T lines, each having one integer which is the number of times the digit appears in the factorial of the first number.
Sample Input
2 5 2 7 0
Sample Output
1 2
题意:求n!中含有x的数量;
#include <iostream>
#include <string.h>
using namespace std;
int a[1005];
void mul(int n){
int left=0;
for (int i=0;i<1000;i++){
a[i]=left+a[i]*n;
left=a[i]/10;
a[i]%=10;
}
}
int main(){
int t,n,x;
cin>>t;
while(t--){
cin>>n>>x;
memset(a,0,sizeof(a));
a[0]=1;
for (int i=2;i<=n;i++){
mul(i);
}
int k=1000;
for (;k>=0;--k){
if (a[k])
break;
}
int count=0;
for (int i=0;i<=k;i++){
if (a[i]==x)
count++;
}
cout<<count<<endl;
}
return 0;
}
本文介绍了一道趣味编程竞赛题目——年度傻瓜大赛,参赛者需计算出生日期对应的天数之阶乘中特定数字出现的次数。文章提供了一个使用C++编写的程序示例,详细展示了如何通过字符串数组实现大数阶乘运算并统计指定数字的出现频率。
467

被折叠的 条评论
为什么被折叠?



