zoukankan      html  css  js  c++  java
  • SGU 154. Factorial

    154. Factorial

    time limit per test: 0.5 sec.
    memory limit per test: 4096 KB
    input: standard input
    output: standard output




    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.

    Input
    One number Q written in the input (0<=Q<=10^8).

    Output
    Write "No solution", if there is no such number N, and N otherwise.

    Sample test(s)

    Input
     
     
    2
     
     

    Output
     
     
    10
     
     

    Author: Andrew V. Lazarev
    Resource: Saratov Subregional School Team Contest, 2002
    Date: Spring, 2002





     1 #include <iostream>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int q;
     9     while(cin>>q)
    10     {
    11         int i,ans,high=2000000000,low=1,mid;
    12         if(q==0) { puts("1"); continue;}
    13         while(low<=high)
    14         {
    15             mid=(low+high)>>1;
    16             int k=1,cnt=0;
    17             for(i=1;k<=mid;i++)
    18             {
    19                 k=k*5;
    20                 cnt+=mid/k;
    21             }
    22             if(cnt>=q)
    23             {
    24                 high=mid-1;
    25             }
    26             else if(cnt<q)
    27             {
    28                 low=mid+1;
    29             }
    30         }
    31         int tek=max(low,max(high,mid));
    32         int Q=0,k=1;
    33         for(i=1;k<=tek;i++)
    34         {
    35             k=k*5;
    36             Q+=tek/k;
    37         }
    38         if(Q==q) printf("%d
    ",tek);
    39         else puts("No solution");
    40     }
    41     return 0;
    42 }

    ---恢复内容结束---

  • 相关阅读:
    jQuery基础
    Jquery正则表达式公式.例子
    jquery对象与js对象的相互转换
    windows用命令结束进程
    禅道 bug指向为数字问题解决过程
    delphi 触摸 手势
    二维码
    PowerDesigner 生成的脚本取掉双引号
    oracle执行sql文件
    fireDAC oracle
  • 原文地址:https://www.cnblogs.com/CKboss/p/3278724.html
Copyright © 2011-2022 走看看