UVA - 10061 How many zero#39;s and how many digits ?

n!=x*b^y,

当x为正整数时,最大的y就是n!末尾0的个数了,

把n,b分别拆成素因子相乘的形式:


比如,


n=5,b=16


n=5,b=2^4,

非常明显,末尾0的个数为0


10进制时,n!=a*10^x

b进制时,n!=c*b^y


非常明显,n!的位数就是最大的x+1

这里计算我用了log,精度设置为1e-9

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
const int inf=(1<<31)-1;
const double eps=1e-9;
vector<int>prime;
void maketable()
{int i,j,n=800;bool iscp[810];memset(iscp,0,sizeof(iscp));for(i=2;i<=n;i++){if(!iscp[i]){prime.push_back(i);for(j=i+i;j<=n;j+=i)iscp[j]=1;}}
}
map<int,int>fn;
map<int,int>fb;
map<int,int>::iterator it;
void debug()
{cout<<"***************"<<endl;for(it=fn.begin();it!=fn.end();it++)cout<<it->first<<"^"<<it->second<<endl;cout<<"***************"<<endl;for(it=fb.begin();it!=fb.end();it++)cout<<it->first<<"^"<<it->second<<endl;cout<<"***************"<<endl;
}
int main()
{//freopen("in","r",stdin);//freopen("out","w",stdout);maketable();int i,j,k,n,b,dg,m,num_zero;double x;while(cin>>n>>b){fn.clear();fb.clear();x=0;for(i=2;i<=n;i++)x+=log10(double(i));dg=int(x/log10(double(b))+eps)+1;m=prime.size();for(i=2;i<=n;i++){k=i;for(j=0;j<m&&k>=prime[j];j++){while(k%prime[j]==0&&k>=prime[j]){fn[prime[j]]++;k/=prime[j];}}}for(i=0;i<m&&b>=prime[i];i++){while(b%prime[i]==0&&b>=prime[i]){fb[prime[i]]++;b/=prime[i];}}//debug();num_zero=inf;for(it=fb.begin();it!=fb.end();it++)num_zero=min(num_zero,fn[it->first]/it->second);cout<<num_zero<<" "<<dg<<endl;}return 0;
}

Problem G

How many zeros and how many digits?

Input: standard input

Output: standard output


Given a decimal integer number you willhave to find out how many trailing zeros will be there in its factorial in a given number system and alsoyou will have to find how many digits will its factorial have in a given number system? You can assume that fora b based number system there are b different symbols to denote values ranging from 0 ... b-1.


Input

There will be several lines of input. Each line makes a block. Each linewill contain a decimal number N (a 20bit unsigned number) and a decimal number B(1<B<=800), which is the base of the number system you have to consider.As for example 5! = 120 (in decimal) but it is 78 in hexadecimal number system.So in Hexadecimal 5! has no trailing zeros


Output

For each line of input output ina single line how many trailing zeros will the factorial of that numberhave in the given number system and also how many digits will the factorial of thatnumber have in that given number system. Separate these two numbers with a single space. You can be surethat the number of trailing zeros or the number of digits will not be greaterthan 2^31-1


Sample Input:

2 10
5 16
5 10

 

Sample Output:

0 1
0 2
1 3
________________________________________________________________________________________
Shahriar Manzoor
16-12-2000

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/281655.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

丁洪波 -- 不要“ 总是拿着微不足道的成就来骗自己”

都市快报实盘大赛25期&#xff1a;于海飞/丁洪波荣获冠亚军 七禾网 时间&#xff1a;2010-11-02 12:47:05 来源&#xff1a;期货中国10月30日下午&#xff0c;2010年浙商期货实盘大赛第三季度&#xff08;都市快报实盘大赛第25期&#xff09;颁奖典礼在天科大厦浙商期货大会议室…

面试专题(Mysql及Mongodb)

2019独角兽企业重金招聘Python工程师标准>>> mysql面试题 1. 各个数据库存储引擎区别 mysql的存储引擎是针对表进行设置的&#xff0c;一个库的不同表可以设置不同的存储引擎&#xff0c;mysql默认支持多种存储引擎&#xff0c;以适用不同领域的数据库应用需要&…

织梦网站翻页php,dedecms织梦网站列表页和内容页分页样式

织梦分页标签{dede:pagelist istitem"index,pre,next,end,option,info," listsize"5"/}&#xff0c;{dede:prenext getpre/}&#xff0c;{dede:prenext getnext/}。默认样式和使用模板css样式布局不一样,这时又不想重写样式&#xff0c;我们可以修改织梦标…

通过中间件添加用户的Claim

本文主要介绍 Sang.AspNetCore.RoleBasedAuthorization[1] 库如何通过中间件实现对用户 Claim 的添加。背景前面我们介绍了通过对自定义授权策略和自定义授权处理程序的使用实现了基本的RBAC权限设计&#xff0c;将大量的用户可访问资源及操作的标识直接放到用户的 JWT Token 中…

部署也是工程的一部分,也要编程(自动化)

部署和开发一样&#xff0c;同样面临变化。同样有复杂的细节。 同样应该代码化&#xff0c;自动化。把复杂性、思路&#xff0c;操作&#xff0c;都固化下来&#xff0c;显式表达。 不要“雪花”式配置。 把最近看的文章摘抄一下 集句&#xff1a; 1频繁做让你感到痛苦的事情&a…

KDD走进阿里 数百专家聚集探讨产学研一体化

6月29日&#xff0c;由阿里巴巴集团、中国中文信息学会、KDD China联合主办的数据挖掘前沿发展与未来论坛在杭州举行&#xff0c;会议吸引了来自国际顶级高校和知名企业的近300名专家学者到场参会、近30000人在线观看。论坛除了分享最新的数据挖掘领域最新科研成果及研发思路外…

zookeeper学习03 使用场景

zookeeper实际应用场景 zookeeper能够实现哪些场景 1&#xff09;订阅发布/配置中心 watcher机制 统一配置管理&#xff08;disconf&#xff09; 实现配置信息的集中式原理和数据的动态更新 实现配置中心有俩种模式&#xff1a;push,pull 长轮询 zookeeper采用的是推拉相结合的…

php模板引擎循环start,PHP模板引擎Smarty内建函数section,sectionelse用法详解

本文实例讲述了PHP模板引擎Smarty内建函数section,sectionelse用法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;section 是 Smarty 模板中除了 foreach 以外的另一种处理循环的方案&#xff0c;section 比 foreach 要灵活&#xff0c;就像是一个改进的 foreach 语句…

OpenHarmony操作系统与龙芯2K1000LA芯片完成适配,龙架构平台获得开源鸿蒙认证

近日&#xff0c;龙芯中科与软通动力控股公司鸿湖万联共同完成OpenHarmony操作系统与龙芯2K1000LA处理器的适配&#xff0c;“乘风1000”开发板&#xff08;搭载龙芯2K1000LA&#xff09;荣获OpenHarmony生态产品兼容性证书。至此&#xff0c;万物互联的OpenHarmony生态体系再次…

struts2开发action 的三种方法以及通配符、路径匹配原则、常量

struts2开发action 的三种方法 1、继承ActionSupport public class UserAction extends ActionSupport {// Action中业务处理方法public String login() {System.out.println("UserAction.login()"); // return "success";return SUCCESS;} } 2、实现…

闭包--闭包作用之保护(一)

闭包作用:保护 形成私有作用域,保护里面的私有变量不受外界干扰例如多人协作开发&#xff1a;A的代码有fn(),B的代码有fn(),但是他们不相互影响 // A的代码<script>(function() {function fn1() {console.log("aa")}window.fn1 fn1;})()// window.fn1() //11&…

left join 和 inner join

2019独角兽企业重金招聘Python工程师标准>>> left join 和 inner join 首先 MySQL 中 inner join 的效率确实要高于 left join。所以没必要使用 left join 转弯成 inner join 的效果。这样不但效率降低&#xff0c;可读性也会降低。 Number1 select from t1 left j…

oracle 数据库中拆分,oracle数据库字符串拆分

第一种 直接返回切分的字符串create or replace function Get_StrArrayLength(av_str varchar2,--要分割的字符串av_split varchar2 --分隔符号)return numberislv_str varchar2(1000);lv_length number;beginlv_str:ltrim(rtrim(av_str));lv_length:0;while instr(lv_str,av_s…

Vue3+.NET6,轻松开发管理后台!(可复用)

在GitHub是没找到简单好用的Vue3.NET6管理后台项目&#xff0c;有收藏的请评论区分享。这里分享一套Vue3 Axios TS Vite Element Plus .NET 6 WebAPI JWT SqlSugar的通用管理后台&#xff0c;前后端分离架构&#xff0c;各种最新框架组件&#xff0c;实现了管理后台几乎…

iOS网络请求安全认证(JWT,RSA)

在网络世界中&#xff0c;安全是一个很重要的问题&#xff0c;以往的HTTP请求已经不能承担这个安全任务&#xff0c;抓包工具一抓&#xff0c;你的所有网络请求全都曝光。当然&#xff0c;你可能会采用加密算法来加密数据&#xff0c;但是这仍然不够。 在移动端和服务器的通信过…

微信小程序黑客马拉松即将开始,来做最酷的 Mini Program Creators!

微信小程序黑客马拉松正式启动 近日&#xff0c;小程序斩获一项世界级殊荣——作为一项全新的技术和应用创新&#xff0c;小程序首次获选世界互联网领先科技成果。目前小程序应用数量已超过 100 万&#xff0c;覆盖了 200 多个细分行业&#xff0c;日活用户达到 2 亿。 微信小程…

oracle 文件写 n r,[oracle]log_archive_dest_n与DB_RECOVERY_FILE_DEST

DB_RECOVERY_FILE_DEST参数是默认的flashrecovery area的路径&#xff0c;里面存放有归档日志、闪回日志以及rman的备份文件等文件。LOG_ARCHIVE_DEST_n参数是存放归档日志的路径&#xff0c;n表示1~10的一个整数&#xff0c;由于归档日志在recovery的时候担当了重要的角色&…

记一次 .NET 某娱乐聊天流平台 CPU 爆高分析

一&#xff1a;背景 1.讲故事前段时间有位朋友加微信&#xff0c;说他的程序直接 CPU100%&#xff0c;每次只能手工介入重启&#xff0c;让我帮忙看下到底怎么回事&#xff0c;哈哈&#xff0c;这种CPU打满的事故&#xff0c;程序员压力会非常大, 我让朋友在 CPU 高的时候抓 2 …

linux下mariadb大小写敏感

2019独角兽企业重金招聘Python工程师标准>>> Linux下安装好mariadb后&#xff0c;在使用时会发现mariadb对大小写敏感&#xff0c;这对开发带来一定的不利&#xff0c;这时只要在配置文件中配置一下&#xff0c;取消大小写敏感即可&#xff1a; sudo vi /etc/MySQL/…

评论列表显示及排序,个人中心显示

1.显示所有评论{% for foo in ques.comments %} 2.所有评论排序uquestion db.relationship(Question, backrefdb.backref(comments, order_bycreat_time.desc)) 3.显示评论条数{{ ques.comments|length }} 1题代码如下&#xff1a; <h3>评论区:({{ ques.comments|length…