前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACMSGURU 154 - Factorial

ACMSGURU 154 - Factorial

作者头像
Reck Zhang
发布2021-08-11 11:13:47
2510
发布2021-08-11 11:13:47
举报
文章被收录于专栏:Reck ZhangReck Zhang

Factorial

Problem Description

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! = 12…*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

Solution

代码语言:javascript
复制
#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);

    int q;
    std::cin >> q;

    if(q == 0) {
        std::cout << 1 << std::endl;
    }

    long long left = 5;
    long long right = 5 * q;
    long long res = -1;
    while(left <= right) {
        long long mid = (left + right) / 2;
        long long tmpMid = mid;
        int count = 0;
        while(tmpMid != 0) {
            tmpMid /= 5;
            count += tmpMid;
        }
        if(count == q) {
            res = mid;
            right = mid - 1;
        } else if(count > q) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }

    if(res == -1) {
        std::cout << "No solution" << std::endl;
    } else {
        std::cout << res << std::endl;
    }

    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-11-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Factorial
    • Problem Description
      • Input
        • Output
          • Sample test(s)
            • Input
              • Output
                • Solution
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档