http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4433

C++版本一

题解:这个题让我想起了https://codeforces.com/contest/837/problem/D

https://blog.csdn.net/weixin_43272781/article/details/84581632

思路差不多,因为这个题5肯定比2少所以只要考虑5就行

不过我考虑了二分答案和每个数字前面5出现的情况所以感觉还行

就是内存有点多,时间有点长

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUGusing namespace std;
typedef long long ll;
const int N=20000000;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m;
int a[N];
int sloved(int x){return x/5+x/25+x/125+x/625+x/3125+x/15625+x/78125+x/390625+x/1953125+x/9765625+x/48828125+x/244140625;
}
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifscanf("%d",&t);int T=0;while(t--){scanf("%d",&n);cout << "Case "<<++T<<": ";int l=5;int r=n*5;int mid ,ans=1;while(l<=r){mid=(l+r)>>1;int tmp=sloved(mid);if(tmp==n){cout << mid-mid%5 << endl;ans=0;break;}else if(tmp<n){l=mid+1;}else{r=mid-1;}}if(ans)cout << "impossible" << endl;}//cout << "Hello world!" << endl;return 0;
}

C++版本二

题解:
二分枚举n,若将阶乘中所有的数拆分成质因子的乘积,发现只有2*5 才能产生
0,同时2 会比5 的个数多。故直接二分n,check 5 的个数。

#include <stdio.h>int five[30];
int total_five;void init(){five[0] = 5;total_five = 1;for(int i = 1; five[i-1]*5ll<1e9; i ++) {five[i] = five[i-1]*5;total_five ++;}
}int get_suff_count(int m){int ret = 0;for(int i = 0; i < total_five; i ++){ret += m/five[i];}return ret;
}int bin(int l, int r, int Q){int ret = -1;while( l <= r){int m = (l+r) >> 1;int suff_count = get_suff_count(m);if(suff_count == Q){ret = m;r = m-1;}else if(suff_count < Q){l = m+1;}else{r = m-1;}}return ret;
}int main(){
//    freopen("data1.in", "r", stdin);
//    freopen("data1.out", "w", stdout);int T, Q;int ica = 1;scanf("%d", &T);init();while( T --){scanf("%d", &Q);int ans = bin(5, 5e8, Q);if(ans == -1) printf ("Case %d: impossible\n", ica ++);else printf("Case %d: %d\n", ica ++, ans);}return 0;
}

C++版本三

题解:模拟一下牛顿迭代,那么可以使得复杂度变得更低。记get(x)为x!中零的个
数。那么答案必定在x~x-(k-get(x))之中。最后注意一下当(k-get(x))小于10
的时候暴力一下。

///O(玄学)
#include<bits/stdc++.h>
using namespace std;int get(int x){int ret = 0;while(x){ret += x;x /= 5;}return ret;
}
int solve(int n){int x = n;while(true){int ret = get(x);if(abs(ret - n) <= 10){for(int i = min(n - ret, 0); i <= max(n - ret, 0); ++i){if(get(x + i) == n) return (x + i) * 5;}return -1;}x -= ret - n;}}
int main()
{
//    freopen("data1.in", "r", stdin);
//    freopen("check1.out", "w", stdout);int t;scanf("%d", &t);for(int cas = 1; cas <= t; ++cas){printf("Case %d: ", cas);int k;scanf("%d", &k);int ans = solve(k);if(ans == -1)   puts("impossible");else    printf("%d\n", ans);}return 0;
}

Suffix Zeroes相关推荐

  1. b. Suffix Zeroes

    b: Suffix Zeroes Time Limit: 1 Sec  Memory Limit: 128 MB Description 这个游戏超休闲的~.现在你需要找一个自然数n,你找的自然数需要 ...

  2. 浅显易懂 Makefile 入门 (06)— 文件名操作函数(dir、notdir、suffix、basename、addsuffix、addperfix、join、wildcard)

    编写 Makefile 的时候,很多情况下需要对文件名进行操作.例如获取文件的路径,去除文件的路径,取出文件前缀或后缀等等. 注意:下面的每个函数的参数字符串都会被当作或是一个系列的文件名来看待. 1 ...

  3. 172. Factorial Trailing Zeroes

    /**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang* 首先别忘了什么是factorial,就是阶乘.那么很容易想到需要统计* (2,5)对的 ...

  4. matlab gcc4.7,关于gcc-4.7.2 cannot compute suffix of object fil...

    打算学习C++ 11,所以要换编译器,下载了最新的源码后,按常规过程编译: 1.解压缩RPM包: [root@linuxopt]# tar xjvf gcc-4.0.1.tar.bz2 (解压后生成源 ...

  5. pandas将列表list插入到dataframe的单元格中、pandas使用read_csv函数读取文件并设置保留数值的前置0( leading zeroes)

    pandas将列表list插入到dataframe的单元格中.pandas使用read_csv函数读取文件并设置保留数值的前置0( leading zeroes) 目录

  6. Pandas批量删除dataframe列名中的后缀实战:使用rstrip函数批量删除列名中的后缀(suffix)、使用replace函数批量删除列名中的后缀(suffix)

    Pandas批量删除dataframe列名中的后缀实战:使用rstrip函数批量删除列名中的后缀(suffix).使用replace函数批量删除列名中的后缀(suffix) 目录

  7. [LeetCode] Factorial Trailing Zeroes

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  8. Bash: Removing leading zeroes from a variable

    old="0004937" # sed removes leading zeroes from stdin new=$(echo $old | sed 's/^0*//') 转载于 ...

  9. suffix tree

    文章出处:http://www.cnblogs.com/snowberg/archive/2011/10/21/2468588.html 3   What is a Suffix Tree Suffi ...

最新文章

  1. Linux下的Mongodb部署应用梳理
  2. Android WebView 图片超出宽度自适应,点击查看大图
  3. Google 修改 Chrome API,防止隐身模式检测
  4. django-学生列表页的制作
  5. 35岁老半路程序员的Python从0开始之路
  6. 正则表达式的三种模式【贪婪、勉强、侵占】的分析
  7. 简单选择排序及其优化
  8. java 自循环_java自学之:循环问题
  9. SSH框架+mysql+tomcat 服务器 中文乱码解决方案
  10. 用计算机模拟宇宙,计算机中的宇宙
  11. 目前最完整的前端框架 Vue.js 全面介绍
  12. java1.7环境_java1.7环境变量设置
  13. 【摩尔吧今日推荐】我们一定要给自己提出这样的任务:第一,学习,第二是学习,第三还是学习。
  14. root 红米note5_红米Note5 root教程_红米Note5卡刷root包来获取root权限
  15. 应急响应 - Windows启动项分析,Windows计划任务分析,Windows服务分析
  16. Android studio下载及安装方法
  17. Empress .... 概念
  18. 优步UBER司机全国各地奖励政策汇总 (4月4日-4月10日)
  19. C#中WebService里的回车符\r丢失问题
  20. 最长回文子串(Python)

热门文章

  1. php8正式版发布,PHP 8.0 正式版发布,性能提升 10%
  2. switch日版有中文吗_任天堂switch国行和日版的区别
  3. 计算 的程序java_数学表达式计算程序(java)
  4. mysql 多久备份一次_教你如何通过一次单击自动备份mysql数据库
  5. ddr传输 pl ps_Vitis ZYNQ开发秘籍 PS 端任意控制 VGA 显示画面最终实现
  6. 淮阳一高2021高考成绩查询,周口教育网2021年淮阳中招成绩查询系统
  7. linux mysql 客户端编码设置_Windows、Linux系统下mysql编码设置方法_MySQL
  8. polkit 重新安装_CentOS Linux 7.4中polkit服务启动失败
  9. apache apollo php,php windows環境 安裝 Apache-apollo + phpMQTT 實現發送 MQTT
  10. 三十九、Vue项目上手 | 用户管理系统 实现添加用户功能(中篇)