Factorial Problem in Base K(zoj3621)
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)的更多相关文章
- 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 ...
- 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 ...
- ZOJ Problem Set - 3829Known Notation(贪心)
ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...
- Problem D: 程序填充(递归函数):数列2项和
Problem D: 程序填充(递归函数):数列2项和 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2601 Solved: 2117 Descrip ...
- Summary—【base】(HTML)
Html知识点: 1. 建议开发人员计算机基本配置 a) 显示所有文件的后缀名* b) 文件的排列方式改为详细信息,并且名称一定要能够全部显示出来 c) 使用小的任务栏 d) 将常用的工具锁定到任务栏 ...
- Summary—【base】(JavaScript)
1.认识Js 1.1 Js就是一门运行在客户端浏览器的脚本编程语言 1.2 组成 ECMAScript:Js的语法标准 DOM:JS操作网页 ...
- Git Base 操作(二)
1. 撤销修改 (1) 当改乱了工作区(working directory)某个文件的内容,想直接丢弃工作区中的修改时,用命令git checkout -- file. (2) 当不但改乱了工作区某个 ...
- Git Base 操作(一)
Git常用命令 1. 命令git init把这个目录变成Git可以管理的仓库: 2. 命令git commit把文件提交到仓库 这里需要注意的是,Git只能跟踪文本文件的改动,如txt文件,网页,所有 ...
- 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 ...
随机推荐
- [实战演练]蜻蜓FM2014年校招笔试题目 - 规则二叉树
题目:某规则二叉树的定义是:对于树中任意两个叶结点A.B,他们与根结点的距离分别是d1和d2,|d1-d2|<=1.请写出函数 bool isRuledTree(Node *root)的代码实现 ...
- 201621123018《Java程序设计》第5周学习报告
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口.interface.implements.Comparable.Comparator. 1.2 尝试使用思维导图将这些关键 ...
- 【文文殿下】WC2019游记
Day0 今天早上三点半才睡着,五点起床,前往省城郑州.与省实验常老师汇合,坐上高铁,下午三点半多才到广州二中. 下午随便找了一个教室进去敲一敲代码,发现自己越来越菜了. 和一大堆网上的dalao面基 ...
- Windows 64位系统安装Apache2.4
Windows 64位系统安装Apache2.4 来自:百度经验:jingyan.baidu.com 现在大部分一键安装包多是32位的,并不支持64位,直接在64位的系统上使用会报错的,所以我这里就来 ...
- nginx和tomcat访问图片和静态页面的配置方法
生产环境下,有时候需要访问图片,正常需要应用ftp.nginx等配套使用,但是有时候为了简化,可以用以下的两种简单的访问,说实话,就是为了偷懒,但是效果是能有的,这就行了,所以今天做这个简化版的方便大 ...
- 关于c++类的一些知识的总结
1.经常会听到“类的声明.类的定义.类的实现”,它们之间有什么不一样? 经过查阅https://www.cnblogs.com/kkshaq/p/4660073.html博客的说法,类的声明是在.h文 ...
- Runtime 全方位装逼指南
Runtime是什么?见名知意,其概念无非就是“因为 Objective-C 是一门动态语言,所以它需要一个运行时系统……这就是 Runtime 系统”云云.对博主这种菜鸟而言,Runtime 在实际 ...
- oracle 切换用户操作--or--sys用户密码忘记
1.sqlplus中以普通用户登录oracle后, 普通用户的登录方式: sqlplus /nolog conn 用户名/密码@IP地址/orcl:1521; 这个时候,想要切换sys用户,conn ...
- C# 泛型类在使用中约束
首先看一下泛型的基本语法 访问修饰符 返回类型 泛型方法名 <T>(T 参数) 1):无法在泛型方法内部给任何 T 类型创建实例的对象,因为在泛型方法内部不知道传进来的对象有哪些构造函 ...
- Android:异步处理之Handler、Looper、MessageQueue之间的恩怨(三)
前言 如果你在阅读本文之前,你不知道Handler在Android中为何物,我建议你先看看本系列的第一篇博文<Android:异步处理之Handler+Thread的应用(一)>:我们都知 ...