joj 1551:Factorial Frequencies

 1551: Factorial Frequencies


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout3s8192K564211Standard

In an attempt to bolster her sagging palm-reading business, Madam Phoenix has decided to offer several numerological treats to her customers. She has been able to convince them that the frequency of occurrence of the digits in the decimal representation of factorials bear witness to their futures. Unlike palm-reading, however, she can't just conjure up these frequencies, so she has employed you to detemine these values.

 

Recall that the definition of n! (that is, n factorial) is just . As she expects to use either the day of the week, the day of the month, or the day of the year as the value of n, you must be able to determine the number of occurrences of each decimal digit in numbers as large as 366 factorial (366!), which has 781 digits.

Input and Output

The input data for the program is simply a list of integers for which the digit counts are desired. All of these input values will be less than or equal to 366 and greater than 0, except for the last integer, which will be zero. Don't bother to process this zero value; just stop your program at that point. The output format isn't too critical, but you should make your program produce results that look similar to those shown below.

 

Madam Phoenix will be forever (or longer) in your debt; she might even give you a trip if you do your job well!

Sample Input

 

3
8
100
0

Sample Output

 

3! --
   (0)    0    (1)    0    (2)    0    (3)    0    (4)    0
   (5)    0    (6)    1    (7)    0    (8)    0    (9)    0
8! --
   (0)    2    (1)    0    (2)    1    (3)    1    (4)    1
   (5)    0    (6)    0    (7)    0    (8)    0    (9)    0
100! --
   (0)   30    (1)   15    (2)   19    (3)   10    (4)   10
   (5)   14    (6)   19    (7)    7    (8)   14    (9)   20
#include<stdio.h>
const int max=1000;
int main()
{
 int i,j,k,n;
 while(scanf("%d",&n)&&n)
 {
  int a[max+1]={0};
  a[max]=1;
  for(i=2;i<=n;i++)
  {
   for(j=max;j>=0;j--)
    a[j]*=i;
   for(j=max;j>=0;j--)
   {
    if(a[j]>=10)
    {
     a[j-1]+=a[j]/10;
     a[j]%=10;
    }
   }
  }//(0)   2
  int s[10]={0};
  int flag=0;
  for(i=0;i<max+1;i++)
  {
   if(a[i]) flag=1;
   if(flag) s[a[i]]++;
  }
  printf("%d! --/n",n);
  printf("   (0)%5d    (1)%5d    (2)%5d    (3)%5d    (4)%5d/n",s[0],s[1],s[2],s[3],s[4]);
  printf("   (5)%5d    (6)%5d    (7)%5d    (8)%5d    (9)%5d/n",s[5],s[6],s[7],s[8],s[9]);
 }
 return 0;
}
  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值