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.pswp.cn/news/281655.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/281655.shtml
英文地址,請注明出處:http://en.pswp.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…