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. .NET MVC 学习笔记(五)— Data Validation

    .NET MVC 学习笔记(五)—— Data Validation 在实际应用中,我们需要对数据进行增查改删业务,在添加和修改过程中,无论你编写什么样的网页程序,都需要对用户的数据进行验证,以确数据 ...

  2. IE9的「console未被定义」错误

    IE从IE8+才支持console物件,但如上图所示,网页明明是IE9标准模式,为什么IE9却说console物件不存在? 但进行侦错,console.log()却又正常! 原因: IE8/IE9要先 ...

  3. 【BZOJ2001】 [Hnoi2010]City 城市建设

    BZOJ2001 [Hnoi2010]City 城市建设 Solution 我们考虑一下这个东西怎么求解? 思考无果...... 咦? 好像可以离线cdq,每一次判断一下如果这条边如果不选就直接删除, ...

  4. 初识node.js(通过npm下载项目依赖的包的过程)

    一.初识node.js 简单的说Node.js 就是运行在服务器端的JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事 ...

  5. ROC,AUC,Precision,Recall,F1的介绍与计算

    1. 基本概念 1.1 ROC与AUC ROC曲线和AUC常被用来评价一个二值分类器(binary classifier)的优劣,ROC曲线称为受试者工作特征曲线 (receiver operatin ...

  6. django基础之一

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  7. Python如何判断字符串中是否有中文

    解决:Python如何判断字符串中是否有中文 In [240]: s Out[240]: '你好aa' In [241]: for i in s: ...: if u'\u4e00' <= i ...

  8. 03-01 Java运算符

    (1)算术运算符 A:+,-,*,/,%,++,-- B:+的用法 a:加法 b:正号 c:字符串连接符 C:/和%的区别 数据做除法操作的时候,/取得是商,%取得是余数 D:++和--的用法 a:他 ...

  9. QT开发环境搭建

    一.Qt发展史 1991年,由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架: 2008年,Nokia从Trolltech公司收购Qt, 并增加LGPL的授权模式: 2011年,Digia从N ...

  10. Quarz.net 设置任务并行和任务串行

    如何设置Quarz.net某个任务完成后再继续执行该任务?  Quarz.net 的任务有并行和串行两种: 并行:一个定时任务,当执行时间到了的时候,立刻执行此任务,不管当前这个任务是否在执行中: 串 ...