博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3331 The Idiot of the Year Contest!
阅读量:2441 次
发布时间:2019-05-10

本文共 1797 字,大约阅读时间需要 5 分钟。

The Idiot of the Year Contest!
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

25 27 0

Sample Output

12

题意:求n!中含有x的数量;

#include 
#include
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<
<

转载地址:http://zfbqb.baihongyu.com/

你可能感兴趣的文章
深刻理解Oracle数据库的启动和关闭(转)
查看>>
将Oracle 10g内置的安全特性用于PHP(转)
查看>>
骇客攻击:跳板攻击与防御(1)(转)
查看>>
JBuilder8配置CVSNT 2.0 (转)
查看>>
SYN Flood攻击的基本原理(转)
查看>>
用dhtml做了一个密码管理器 (转)
查看>>
Php 3.x与4.x中关于对象编程的不兼容问题 (转)
查看>>
Cg FAQ (转)
查看>>
在access中增加农历支持模块. (转)
查看>>
增加一个判断内存变量存在的函数 (转)
查看>>
ASP文件上传神功 第二重(招势图加内功心法) (转)
查看>>
JSR227:J2EE数据绑定及数据访问标准 (转)
查看>>
Sun ONE Studio 4 Mobile Edition开发MIDlet入门 (转)
查看>>
Jbuilder8开发J2ee学习笔记(2) (转)
查看>>
Makefile编写小说(一) (转)
查看>>
ORACLE SQL性能优化系列 (二) (转)
查看>>
控件treeview的使用 (转)
查看>>
运用VC或Java对Office进行编程操作 (转)
查看>>
Linux Shell 裡一些很少用到卻很有用的指令 (转)
查看>>
第10章 模型管理视图 (转)
查看>>