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/onlinejudge/showProblem.do?problemCode=3621
Description
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
HINT
题意
给你个在k进制下的数S,然后求S!在K进制下,有多少个末尾0
题解:
首先在10进制下,我们是怎么做的?我们先对10进行了质因数分解,分解成了2和5,然后我们就统计s!中,2和5各有多少个,然后取最少的就好了
就这样,我们先对k进行质因数分解,然后我们取最少个数就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s;
int n;
const int p[]={,,,,,,,,,,,,,,,,,};
int a[];
int main()
{
while(cin>>s>>n)
{
memset(a,,sizeof(a));
ll tmp=;
ll k=;
for(int i=s.size()-;i>=;i--)
{
if(s[i]<=''&&s[i]>='')
tmp+=(s[i]-'')*k;
else if(s[i]<='Z'&&s[i]>='A')
tmp+=(s[i]-'A'+)*k;
else
tmp+=(s[i]-'a'+)*k;
k*=n;
}
for(int i=;i<;i++)
{
while(n%p[i]==&&n>)
{
n/=p[i];
a[i]++;
}
}
ll ans=(1LL<<)-;
for(int i=;i<;i++)
{
ll now=tmp,tot=;
while(now>)
{
now/=p[i];
tot+=now;
}
if(a[i]>)
ans=min(ans,tot/a[i]);
}
printf("%lld\n",ans);
} }
zoj 3621 Factorial Problem in Base K 数论 s!后的0个数的更多相关文章
- 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 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- hdu6003 Problem Buyer 贪心 给定n个区间,以及m个数,求从n个区间中任意选k个区间,满足m个数都能在k个区间中找到一个包含它的区间,如果一个区间包含了x,那么 该区间不能再去包含另一个数,即k>=m。求最小的k。如果不存在这样的k,输出“IMPOSSIBLE!”。
/** 题目:hdu6003 Problem Buyer 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6003 题意:给定n个区间,以及m个数,求从n个区 ...
- 剑指offer12:求解double类型的浮点数base和int类型的整数exponent的次方。 保证base和exponent不同时为0
1. 题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方.保证base和exponent不同时为0. 2. 思路和方法 分析: 由于 ...
- [笔记] $f(i)$ 为 $k$ 次多项式,$\sum_{i=0}^nf(i)\cdot q^i$ 的 $O(k\log k)$ 求法
\(f(i)\) 为 \(k\) 次多项式,\(\sum_{i=0}^nf(i)\cdot q^i\) 的 \(O(k\log k)\) 求法 令 \(S(n)=\sum_{i=0}^{n-1}f(i ...
- 【贪心+中位数】【新生赛3 1007题】 Problem G (K)
Problem G Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- ZOJ 3362 Beer Problem(SPFA费用流应用)
Beer Problem Time Limit: 2 Seconds Memory Limit: 32768 KB Everyone knows that World Finals of A ...
- BZOJ2301/LG2522 「HAOI2011」Problem B 莫比乌斯反演 数论分块
问题描述 BZOJ2301 LG2522 积性函数 若函数 \(f(x)\) 满足对于任意两个最大公约数为 \(1\) 的数 \(m,n\) ,有 \(f(mn)=f(m) \times f(n)\) ...
- zoj 2112 动态区间求第k大
题目大意: 动态单点更新,然后多次询问求区间内第k大 这里单个的主席树不能实现,这里采取的是树状数组套主席树 首先可以想的是将静态主席树先构建好,不去动它,这里空间复杂度就是O(nlogn),这个只要 ...
随机推荐
- 教你如何修改FireFox打开新标签页(NewTab Page)的行列数
FireFox的打开新建标签页(即NewTab Page)默认只能显示3x3个网站缩略图,这9个自定义的网站,非常方便快捷,什么hao123的弱爆了,本人从未用过此类导航网站,曾经用过的也只是abou ...
- FAQ1: 列表索引和切片问题
问题1. 超过列表成员个数的索引访问列表会出现IndexError错误,但是如果用切片去访问就不会报错,而是返回一个空列表.同样元组也是. >>> a=[1,2,3,4] >& ...
- 将table导出为excel格式文件
html: <table cellpadding="0" cellspacing="0" class="data_table" id= ...
- 看懂 MySQL 慢查询日志
MySQL中的日志包括: 错误日志.二进制日志.通用查询日志.慢查询日志等等. 这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1)通用查询日志:记录建立的客户端连接和执行的语句. 2) ...
- ubuntu 上 安装多个php版本
Ubuntu上官方的源,比如 Ubuntu14.04 默认源中的是 PHP5.6.x.Ubuntu16.04 默认源中的是 PHP7.0.x,那么如果想在 Ubuntu16.04 上安装 PHP7.1 ...
- Hadoop案例(八)辅助排序和二次排序案例(GroupingComparator)
辅助排序和二次排序案例(GroupingComparator) 1.需求 有如下订单数据 订单id 商品id 成交金额 0000001 Pdt_01 222.8 0000001 Pdt_05 25.8 ...
- 小甲鱼Python笔记(类)
类和对象 类的构造方法 def __init__(): 1 class People: 2 def __init__(self,name): 3 self.name = name 注意:在构造方法中的 ...
- ArrayList or LinkedList
ArrayList or LinkedList import java.util.*; public class TestArrayLinked { public static void main(S ...
- 网站优化:引用CDN公共库
什么是CDN公共库? CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用.与将JS库存放在服务器单机上相比,CDN公共库更加稳定.高速.一般的CDN公共库都会包含全球所有最流行的 ...
- Building Robust and Flexible Event System in Unity3D
Building Robust and Flexible Event System in Unity3D 1. Prerequisites 1.1 Observer Pattern According ...