问n! 转化成k进制后的位数和尾数的0的个数。【UVA 10061 How many zeros and how many digits?】

Given a decimal integer number you will have to find out how many trailing zeros will be there in its
factorial in a given number system and also you will have to find how many digits will its factorial have
in a given number system? You can assume that for a b based number system there are b different
symbols to denote values ranging from . . . b − .
Input
There will be several lines of input. Each line makes a block. Each line will contain a decimal number
N (a 20bit unsigned number) and a decimal number B ( < B ≤ ), which is the base of the number
system you have to consider. As for example ! = (in decimal) but it is in hexadecimal number
system. So in Hexadecimal ! has no trailing zeros.
Output
For each line of input output in a single line how many trailing zeros will the factorial of that number
have in the given number system and also how many digits will the factorial of that number have in
that given number system. Separate these two numbers with a single space. You can be sure that the
number of trailing zeros or the number of digits will not be greater than − .
Sample Input Sample Output
#include <stdio.h>
#include <math.h> int cal_digit(int n, int b)
{
int i;
double l;
for (i = , l = ; i <= n; i++)
l += log10(i) / log10(b);
return l + ;
} int cal_zero(int n, int b)
{
int i, d, m, t;
for (i = , d = ; i <= b; i++) {
m = ;
while (b % i == ) {
m++;
d = i;
b /= i;
}
}
for (t = ; n > ; ) {
t += n / d;
n /= d;
}
return t / m;
} int main(void)
{
int n, b;
while (scanf("%d%d", &n, &b) != EOF)
printf("%d %d\n", cal_zero(n, b), cal_digit(n, b));
return ;
}

UVA

n! 在k进制下后缀0的个数。【洛谷 一道中档题】

输入输出格式
输入格式:
每组输入仅包含一行:两个整数n,k。 输出格式:
输出一个整数:n!在k进制下后缀0的个数。 输入输出样例
输入样例#1:
10 40
输出样例#1:
2
说明
对于20%的数据,n <= 1000000, k = 10 对于另外20%的数据,n <= 20, k <= 36 对于100%的数据,n <= 10^12,k <= 10^12

  


给出一个k进制的数n,求n!里一共有多少个0。【ZOJ Factorial Problem in Base K】

https://www.cnblogs.com/linqiuwei/p/3258408.html 【好解释】

先把n转化为10进制下的数。

把n!分解质因数。

把k分解质因数。

求所有的k的质因数中,除以n!的相同质因数中最小的。就是answer。

  

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

  

//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

n!在k进制下的后缀0的更多相关文章

  1. 求x!在k进制下后缀零的个数(洛谷月赛T1)

    求x!在k进制下后缀和的个数 20分:     求十进制下的x!后缀和的个数 40分: 高精求阶乘,直接模拟过程 (我不管反正我不打,本蒟蒻最讨厌高精了) 60分     利用一个定理(网上有求x!在 ...

  2. bzoj 3000 Big Number 估算n!在k进制下的位数 斯特林公式

    题目大意 求n!在k进制下的位数 2≤N≤2^31, 2≤K≤200 分析 作为数学没学好的傻嗨,我们先回顾一下log函数 \(\log_a(b)=\frac 1 {log_b(a)}\) \(\lo ...

  3. 51 Nod 1116 K进制下的大数

    1116 K进制下的大数  基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 有一个字符串S,记录了一个大数,但不知这个大数是多少进制的,只知道这个数 ...

  4. 陕西师范大学第七届程序设计竞赛网络同步赛 F WWX的礼物【数学/k进制下x^n的位数/log】

    链接:https://www.nowcoder.com/acm/contest/121/F来源:牛客网 题目描述 WWX的女朋友送给了他一个礼物,可是礼物却被一把K进制密码锁锁住了.在礼物盒上还有一张 ...

  5. light oj 1045 - Digits of Factorial K进制下N!的位数

    1045 - Digits of Factorial Factorial of an integer is defined by the following function f(0) = 1 f(n ...

  6. 数位DP 求K进制下0~N的每个数每位上出现的数的总和

    好久没写博客了,因为感觉时间比较紧,另一方面没有心思,做的题目比较浅也是另一方面. 热身赛第二场被血虐了好不好,于是决定看看数位DP吧. 进入正题: 如题是一道经(简)典(单)的数位dp. 第一步,对 ...

  7. [51nod1116]K进制下的大数

    解题关键:$A\% (k - 1) = (A[0] + A[1]*k + A[2]*{k^2} + ...A[n]*{k^n})\% (k - 1) = (A[0] + A[1] + ...A[n]) ...

  8. 51nod 1116 K进制下的大数

    你万万想不到,Long Long 就能存下的数据 #include <iostream> #include <cstdio> #include <cstdlib> ...

  9. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

随机推荐

  1. 动态规划:HDU1248-钱币兑换问题

    解题心得: (青蛙跳台阶:有n阶台阶,青蛙可以一次跳一阶也可以一次跳两阶,问总共有多好中跳法) 1.之前把这个问题的思路弄错了,以为是递推,就像青蛙跳台阶,用斐波那契求解.但是用斐波那契肯定会超范围. ...

  2. ZOJ 3231 Apple Transportation 树DP

    一.前言 红书上面推荐的题目,在138页,提到了关键部分的题解,但是实际上他没提到的还有若干不太好实现的地方.尤其是在这道题是大家都拿网络流玩弄的大背景下,这个代码打不出来就相当的揪心了..最后在牛客 ...

  3. python单元测试用例

    demo1.py #!/usr/bin/python # encoding: utf-8 def hello(): print "i am in demo1" def add(x, ...

  4. go经典练习题涉及流程控制-字符串-struct-map的数据类型的处理

    one:求1到100之间的质数 package main import ( "fmt" ) func isPrime(n int) bool { var flag = true f ...

  5. laravel5.2总结--邮件

    laravel自带SwiftMailer库,集成了多种邮件API,支持多种邮件驱动方式,包括smtp.Mailgun.Maildrill.Amazon SES.mail和sendmail,Mailgu ...

  6. psql 工具详细使用介绍

    psql 介绍 psql 是 PostgreSQL 中的一个命令行交互式客户端工具, 它允许你交互地键入 SQL 命令,然后把它们发送给 PostgreSQL 服务器,再显示 SQL 或命令的结果. ...

  7. maven学习(八)——使用maven创建javaweb项目

    构建JavaWeb项目 1.创建JavaWeb项目 1.使用mvn archetype:generate命令,如下所示: mvn archetype:generate -DgroupId=com.my ...

  8. selenium webdriver——元素定位

    元素定位: >>WebDriver提供了八种元素定位方法,在Python语言中,所对应的方法如下: >>id属性定位:有唯一性 find_element_by_id(" ...

  9. 【转】Using Raycasts and Dynamically Generated Geometry to Create a Line of Sight on Unity3D

    http://www.linkedin.com/pulse/using-raycasts-dynamically-generated-geometry-create-line-thomas José ...

  10. 【bzoj2186】[Sdoi2008]沙拉公主的困惑 欧拉函数

    题目描述 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为1到N的阶乘,但是,政府只发行编号与M!互质的钞票.房地产第一大户沙拉公主决定预测一下大富翁国现在所有真钞票的 ...