题目链接:点击打开链接

题目的意思就是:给一个k进制的数s,求s!在10 进制下的末尾0个数。

思路:

先把s转化为10进制下的数。

把n!分解质因数。

把k分解质因数。

求所有的k的质因数中,除以n!的相同质因数中最小的。就是answer。

例如:

看这组数据:10 10.

s本来就是10进制下的。所以不用转化。

10!=2^8*3^4*5^2*7

10=2*5;

看10 的质因数2为1个,对应的10!的的质因数2的个数为8. 8/1=8;

再看质因数5为1个,对应的           的质因数5的个数为2. 2/1=2;

所以answer=2;

描述不好。

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define LL long long
const int N=105;
map<int,int> M;LL f(char *s,int k){LL len=strlen(s),n=0,mid=1;for(int i=len-1;i>=0;i--){n+=(mid*M[s[i]]);mid=mid*k;}return n;
}LL f1(LL x,int k){if(x<k) return 0;return x/k+f1(x/k,k);
}int Prime[20];
int top;
bool Judge(int x){int i;for(i=2;i<=(int)sqrt(x)&&x%i!=0;i++);if(i>(int)sqrt(x)) return true;return false;
}void Init(){top=0;for(int i=2;i<=62;i++)if(Judge(i)) Prime[top++]=i;top=top-1;
}int main(){Init();//A B C D E F G H I J K L M N O P Q R S T U V W X Y ZM['0']=0;M['1']=1;M['2']=2;M['3']=3;M['4']=4;M['5']=5;M['6']=6;M['7']=7;M['8']=8;M['9']=9;M['A']=10;M['B']=11;M['C']=12;M['D']=13;M['E']=14;M['F']=15;M['G']=16;M['H']=17;M['I']=18;M['J']=19;M['K']=20;M['L']=21;M['M']=22;M['N']=23;M['O']=24;M['P']=25;M['Q']=26;M['R']=27;M['S']=28;M['T']=29;M['U']=30;M['V']=31;M['W']=32;M['X']=33;M['Y']=34;M['Z']=35;M['a']=36;M['b']=37;M['c']=38;M['d']=39;M['e']=40;M['f']=41;M['g']=42;M['h']=43;M['i']=44;M['j']=45;M['k']=46;M['l']=47;M['m']=48;M['n']=49;M['o']=50;M['p']=51;M['q']=52;M['r']=53;M['s']=54;M['t']=55;M['u']=56;M['v']=57;M['w']=58;M['x']=59;M['y']=60;M['z']=61;char str[N];int k;while(~scanf("%s%d",str,&k)){LL n=f(str,k);//先把k进制的数转化成10进制的.LL num1[top+1],num2[top+1];memset(num1,0,sizeof(num1));memset(num2,0,sizeof(num2));for(int i=0;i<=top;i++){//将n分解质因数.num1[i]=f1(n,Prime[i]);}for(int i=0;i<=top;i++){//将k分解质因数.while(k%Prime[i]==0) {num2[i]++;k/=Prime[i];}}LL ans=-1;for(LL i=0;i<=top;i++){if(num1[i]&&num2[i]){if(ans==-1) {ans=num1[i]/num2[i];continue;}ans=min(ans,num1[i]/num2[i]);}}if(ans==-1) printf("0\n");else printf("%lld\n",ans);}return 0;
}

zoj 4745 Factorial Problem in Base K相关推荐

  1. zoj 3621 Factorial Problem in Base K 数论 s!后的0个数

    Factorial Problem in Base K Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onli ...

  2. ZOJ - 4049 Halting Problem 题解【c++】

    题目如下: In computability theory, the halting problem is the problem of determining, from a description ...

  3. Problem B: 第K位数字

    Problem Description 编写函数digit(n, k),使得函数返回正整数 n 中的第 k 位数字(从右边算起).如果 k 大于 n 所含有的数字个数,函数返回 0 .  测试程序为: ...

  4. zoj 3798 Abs Problem(数学:推理+滚动数组)

    题意是给定n个数,定义一种运算为每次取当前数和下一个数的差的绝对值作为下一次运算的当前数 输出最小值,最大值以及对应的路径 感觉很犀利的一道题,但是比赛的时候AC率特别高... 我用了一个多小时才写出 ...

  5. XidianOJ 1123 K=1 Problem of Orz Pandas

    题目描述 One panda named orz is playing a interesting game, he gets a big integer Num and an integer K. ...

  6. poj 1436 zoj 1391 Horizontally Visible Segments (Segment Tree)

    ZOJ :: Problems :: Show Problem 1436 -- Horizontally Visible Segments 用线段树记录表面能被看见的线段的编号,然后覆盖的时候同时把能 ...

  7. *【CF#633B】 A Trivial Problem(二分或枚举)

    题干: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them ...

  8. poj 1689 zoj 1422 3002 Rubbery (Geometry + BFS)

    ZOJ :: Problems :: Show Problem 1689 -- 3002 Rubbery 这题是从校内oj的几何分类里面找到的. 题意不难,就是给出一个区域(L,W),这个区域里面有很 ...

  9. ZOJ Monthly, August 2012 题解

    A: 题目链接:点击打开链接 Alice's present #include <cstdio> #include <iostream> #include <cstrin ...

最新文章

  1. R语言使用ggplot2包使用geom_dotplot函数绘制分组点图(添加均值、中位数)实战(dot plot)
  2. 使用Oracle 的 imp ,exp 命令实现数据的导入导出
  3. linux ss 命令简介 端口连接查看 代替netstat
  4. wxPython:事件
  5. 海致java面试_海致面试
  6. Lumen开发:如何向 IoC 容器中添加自己定义的类
  7. windows 通过批处理 修改环境变量
  8. 人工智障学习笔记——深度学习(2)卷积神经网络
  9. XHTML 教程 续一
  10. Java Properties 与 ResourceBundle、ClassLoader 类加载器
  11. 优秀架构师是怎么炼成的?
  12. openpyxl 简单使用
  13. STM32电机TB6612驱动
  14. 数据挖掘 / 机器学习——决策树
  15. 扩展坞可以把手机投到显示器吗_华为P20投屏助手,绿联USB-C扩展坞使用说明
  16. 如何搭建APP分发平台分发平台搭建教程
  17. 互联网支付系统整体架构
  18. 我去图书馆微信公众号抢座【Python版本】
  19. 红米note10和红米note8pro哪个好
  20. 怎样清理苹果电脑磁盘空间_Mac启动磁盘已满?如何快速清理电脑磁盘

热门文章

  1. Python numpy中random函数的使用
  2. 人生苦短、我爱python_人生苦短,我爱Python007——基本语法(5)
  3. 软件测试之软件测试用例
  4. OGG mgr定期清理tail 文件
  5. Hexo攻略-更换网页图标
  6. trunk和acces
  7. 【理财知识】什么是溢价率?
  8. 关于setTimeout函数中的this指向问题
  9. web服务器可以上传信息吗,Web服务器的架设上传.doc
  10. 新买了一台SONY电视机 里面居然没有KODI自己装