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. 多项式&生成函数(~~乱讲~~)

    多项式 多项式乘法 FFT,NTT,MTT不是前置知识吗?随便学一下就好了(虽然我到现在还是不会MTT,exlucas也不会用) FTT总结 NTT总结 泰勒展开 如果一个多项式\(f(x)\)在\( ...

  2. gunicorn运行显示connection in use解决办法

    运行gunicorn后显示如下错误: root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# gunicorn -w 4 -b 0.0.0.0:5000 myapp:app ...

  3. 堆排序(大顶堆、小顶堆)----C语言

    堆排序 之前的随笔写了栈(顺序栈.链式栈).队列(循环队列.链式队列).链表.二叉树,这次随笔来写堆 1.什么是堆? 堆是一种非线性结构,(本篇随笔主要分析堆的数组实现)可以把堆看作一个数组,也可以被 ...

  4. spring boot实现异步调用

    今天在这里学习下使用springboot的异步调用async 首先使用@EnableAsync开启异步功能 /** * @author fengzp * @date 17/5/8 * @email f ...

  5. django基础之一

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

  6. 关于AOP的PIAB

    AOP:面向切面编程,也就是在运行过程中,按照需要动态加载功能块 PIAB:含义可以从下面提取 Microsoft Patterns & Practices团队在2007年发布的Enterpr ...

  7. 在mac上安装xcode时 弹出需要关闭itunes的警告 解决办法

    1  首先打开终端(在工具栏中:前往-->使用工具-->终端) 2  输入 ps -ef | grep iTunes 回车  501   300   207   0 11:58上午 ??  ...

  8. POJ 2405

    #include <iostream> #include <cmath> #include <iomanip> #define pi 3.1415926536 us ...

  9. 深入聊聊Java多线程

    一.背景 在没有学习Java多线程以前,总觉得多线程是个很神秘的东西,只有那些大神才能驾驭,新年假期没事就来学习和了解一下Java的多线程,本篇博客我们就来从头说一下多线程到底是怎么回事. 二.概述 ...

  10. tabs高度自适应方法

    1.去掉easyui-tabs类属性,改为id=tabs 2.用js控制高度