Factorial Problem in Base K


Time Limit: 2 Seconds Memory Limit: 65536 KB

How many zeros are there in the end of s! if both s and s! are written in base k which is not necessarily to be 10? For general base, the digit order is 0-9,A-Z,a-z(increasingly), for example F4 in base 46 is actually 694 in base 10,and f4 in base 46 is 1890 in base 10.

Input

There are multiple cases(less than 10000). Each case is a line containing two integers s and k(0 ≤ s < 2^63, 2 ≤ k ≤ 62).

Output

For each case, output a single line containing exactly one integer in base 10 indicating the number of zeros in the end of s!.

Sample Input

101 2
12 7

Sample Output

3
1

题意:给你s和k表示k进制的s;现在求s的10进制的阶乘换成k进制后末尾有几个0; 思路:找k进制的质因子个数kv[i],以及s的阶乘中质因子的个数pn,那么最后换成k进制后有多少个0,就是pn/kv[i]中最小的。 刚开始找出来pn的时候,测试数据都过了,可是WA了,,,,后来我把ans开很大很大,结果就过了。郁闷
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#define N 65
using namespace std;
char str[N];
int k;
long long s;
int prm[]= {,,,,,,,,,,,,,,,,,},kv[];
/*
int judge(int x,int tp)
{
int y=x,a=0;
while(y<=tp)
{ a+=tp/y;
// printf("y:%d\ttemp:%d ans:%d\n",y,temp,ans);
if(tp/y<x)
break;
y*=x;
}
return a;
}*/
void solve(long long x)
{
int i;
long long res,ans=0x7ffffffffffffff;//开小了,,居然WA
long long pn;
for(i=; i<; i++)
{
res=x;
res=res/prm[i];
pn=res;
while(res)
{
res=res/prm[i];
pn+=res;
}
if(kv[i]&&pn/kv[i]<ans) ans=pn/kv[i];
}
printf("%lld\n",ans);
}
int main()
{
int i,j;
while(scanf("%s%d",str,&k)!=EOF)
{
int len=strlen(str);
s=;
for(i=; i<len; i++)
{
int num;
if(str[i]<='z'&&str[i]>='a')
num=str[i]-'a'+;
else if(str[i]<='Z'&&str[i]>= 'A')
num=str[i]-'A'+;
else
num=str[i]-'';
s=num+s*k;
}
memset(kv,,sizeof(kv));
int n=k,x;
for(i=; i<; i++)
{
while(n%prm[i]==)
{
kv[i]++;
n/=prm[i];
}
}
solve(s);
}
return ;
}
记得以前也做过类似的题。就是求阶乘中含多少质因子的题目。

Factorial Problem in Base K(zoj3621)的更多相关文章

  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. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...

  3. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  4. Problem D: 程序填充(递归函数):数列2项和

    Problem D: 程序填充(递归函数):数列2项和 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2601  Solved: 2117 Descrip ...

  5. Summary—【base】(HTML)

    Html知识点: 1. 建议开发人员计算机基本配置 a) 显示所有文件的后缀名* b) 文件的排列方式改为详细信息,并且名称一定要能够全部显示出来 c) 使用小的任务栏 d) 将常用的工具锁定到任务栏 ...

  6. Summary—【base】(JavaScript)

    1.认识Js     1.1 Js就是一门运行在客户端浏览器的脚本编程语言     1.2 组成            ECMAScript:Js的语法标准            DOM:JS操作网页 ...

  7. Git Base 操作(二)

    1. 撤销修改 (1) 当改乱了工作区(working directory)某个文件的内容,想直接丢弃工作区中的修改时,用命令git checkout -- file. (2) 当不但改乱了工作区某个 ...

  8. Git Base 操作(一)

    Git常用命令 1. 命令git init把这个目录变成Git可以管理的仓库: 2. 命令git commit把文件提交到仓库 这里需要注意的是,Git只能跟踪文本文件的改动,如txt文件,网页,所有 ...

  9. n=C(2,n)+k(构造)( Print a 1337-string)Educational Codeforces Round 70 (Rated for Div. 2)

    题目链接:https://codeforc.es/contest/1202/problem/D 题意: 给你一个数 n ( <=1e9 ),让你构造137713713.....(只含有1,3,7 ...

随机推荐

  1. 关于ajax访问webservice查询数据量稍微大一点,就会返回error500的解决方案

    只需要在web.config的configeration节点中增加如下子节点即可: <system.web.extensions>       <scripting>      ...

  2. 记一次线上事故的JVM内存学习

    今天线上的hadoop集群崩溃了,现象是namenode一直在GC,长时间无法正常服务.最后运维大神各种倒腾内存,GC稳定后,服务正常.虽说全程在打酱油,但是也跟着学习不少的东西. 第一个问题:为什么 ...

  3. day 73 初学vue (1)

    前情提要: vue 框架的初学习, 主要是,指令,属性,函数,计算属性,监听属性,钩子,生命周期,过滤器,阻止事件和综合案例todo list 学习准备,感谢学习资源: vue 官网:https:// ...

  4. 彻底弄懂“PKIX path building failed”问题

    SSL的基础知识 SSL的全称是Secure Socket Layer.它的通信流程如下图所示,客户端与服务端会通过几次通信,通过非对称加密创建出一个加密密钥,用于以后的对称信息加密. 1,客户端明文 ...

  5. swiper4-vue 不使用loop,由最后一张跳到第一张

    <template> <div class="swiper-box"> <div class="swiper-container" ...

  6. javascript数据结构与算法---二叉树(查找最小值、最大值、给定值)

    javascript数据结构与算法---二叉树(查找最小值.最大值.给定值) function Node(data,left,right) { this.data = data; this.left ...

  7. How to resize or create a thumbnail image from file stream on UWP

    最近在搞Ocr相关的windows universal app, 用到了一些图像处理相关的知识. 涉及到了BitmapDecoder/BitmapEncoder/IRandomAccessStream ...

  8. SVN Hooks的介绍及使用

    阅读此篇文章你可以: 对SVN Hooks有一定的了解 获取两个最常用的SVN Hooks案例 SVN hooks介绍 Hooks 钩子,主要实现的功能就是在特定事件发生之前或者之后自动执行事先定义好 ...

  9. mongo学习使用记录2 spring data

    spring data mongo 打印mongo NoSql语句 log4j.properties log4j.rootLogger=INFO, stdout log4j.logger.org.sp ...

  10. HTML Dog 初级教程中关于 forms 的翻译

    Formsforms用于搜集用户输入网页上的信息.它们可以当作网络应用的接口,或者用于发送网络数据. 仅仅使用forms,它们并不那么有用.它们通常结合某种编程语言来处理用户输入的数据.HTML中使用 ...