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 ...
随机推荐
- VS2015ASP.NET MVC5项目中Spring.NET配置方法(超详细)
首先,在ASP.NET MVC5项目右键,如下图所示,选择“管理Nuget程序包...” 然后,在弹出的页面的搜索框中输入“spring.web”,在返回结果中选择Spring.Web和Spring. ...
- .NET MVC 学习笔记(四)— 基于Bootstarp自定义弹出框
.NET MVC 学习笔记(四)—— 基于Bootstarp自定义弹出框 转载自:https://www.cnblogs.com/nele/p/5327380.html (function ($) { ...
- MVC 视图不使用模板页的两种方法
直接对view页面的Layout值设置null @{ Layout = null;//"~/Views/Shared/_Layout.cshtml"; } 对_ViewStart. ...
- 使用Code First建模自引用关系笔记
原文链接 一.Has方法: A.HasRequired(a => a.B); HasOptional:前者包含后者一个实例或者为null HasRequired:前者(A)包含后者(B)一个不为 ...
- MariaDB 表的基本操作(3)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...
- C语言判断进程是否存在
#include <windows.h> #include <tlhelp32.h> //进程快照函数头文件 #include <stdio.h> bool get ...
- Android动画Animation简单示例
Animation是Android给我们提供的一个可以实现动画效果的API,利用Animation我们可以实现一系列的动画效果,比如缩放动画,透明度动画,旋转动画,位移动画,布局动画,帧动画等等.An ...
- Spring 全局异常处理
[参考文章]:Spring全局异常处理的三种方式 [参考文章]:Spring Boot 系列(八)@ControllerAdvice 拦截异常并统一处理 [参考文章]:@ControllerAdvic ...
- Javascript如何避免连续调用中取到不存在的属性而导致报TypeError错?
背景: 在最近的 NODEJS 项目中,涉及到数据库的查询,回调函数里返回了查询结果,我这样做处理然后返回给前端: return results.collect_coupon[0].count 但是这 ...
- python多线程--Condition(条件对象)
Condition class threading.Condition(lock=None 这个类实现条件变量对象.条件变量允许一个或多个线程等待,知道它们被另一个线程唤醒. 如果给出了lock参数而 ...