https://codeforces.com/contest/1114/problem/C

很有趣的一道数论,很明显是要求能组成多少个基数。

可以分解质因数,然后统计各个质因数的个数。

比如8以内,有8/2=4个2+8/4=2个2+8/8=1个2,这样统计是log复杂的。

需要小心的是乘法爆ll的情况,实际上改成从最高的开始往下除可以避免。

然后求这些质因数分解是b的质因数分解的几倍。

然后还有一个bug就是,当n!中缺少b的某个或全部因子时,问题很大。

#include<bits/stdc++.h>
using namespace std;
#define ll long long ll n,b,cb; map<ll,ll> m;
map<ll,ll> m2; void fenjieb(){
m.clear();
cb=b;
ll ceil=sqrt(b+0.001);
for(ll i=;i<=ceil;i++){
while(b%i==){
b/=i;
m[i]++;
}
}
if(b!=)
m[b]++;
b=cb;
} ll countd(){
m2.clear();
for(auto i:m){
ll ii=i.first;
ll cn=n;
int cnt=; //bug1
while(cn>=i.first){
cn/=i.first,cnt++;
} for(int p=;p<cnt;p++){
m2[i.first]+=n/ii;
//cout<<"+"<<ii<<": "<<n/ii<<endl;
ii*=i.first;
}
} /*for(auto i:m){
cout<<i.first<<": "<<i.second<<endl;
} for(auto i:m2){
cout<<i.first<<": "<<i.second<<endl;
}*/ ll minnum=;
if(!m2.empty()) //bug2
minnum=(*m2.begin()).second;
for(auto i:m){
if(m2.count(i.first)) //bug3
minnum=min(m2[i.first]/i.second,minnum);
else
return ;
} return minnum;
} ll solve(){
fenjieb();
return countd();
} int main(){
while(cin>>n>>b){
cout<<solve()<<endl;
}
}

Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论的更多相关文章

  1. CF#538(div 2) C. Trailing Loves (or L'oeufs?) 【经典数论 n!的素因子分解】

    任意门:http://codeforces.com/contest/1114/problem/C C. Trailing Loves (or L'oeufs?) time limit per test ...

  2. CF 1114 C. Trailing Loves (or L'oeufs?)

    C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...

  3. C. Trailing Loves (or L'oeufs?) (质因数分解)

    C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...

  4. Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

    大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...

  5. 【Codeforces 1114C】Trailing Loves (or L'oeufs?)

    [链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...

  6. Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?) (分解质因数)

    题目:http://codeforces.com/problemset/problem/1114/C 题意:给你n,m,让你求n!换算成m进制的末尾0的个数是多少(1<n<1e18    ...

  7. C. Trailing Loves (or L'oeufs?)

    题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...

  8. Trailing Loves (or L'oeufs?)

    The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...

  9. Codeforces1114C Trailing Loves (or L'oeufs?)

    链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...

随机推荐

  1. [React] Use React.memo with a Function Component to get PureComponent Behavior

    A new Higher Order Component (HOC) was recently released in React v16.6.0 called React.memo. This be ...

  2. SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir

    读写sd卡中的文件依照例如以下步骤:1调用Environment的getExternalStorageState()方法推断手机上是否插入了sd卡.而且应用程序具有读写SD卡的能力 //假设手机已经插 ...

  3. spi flash 操作

    W25Q16V 是华邦出的一颗 spi flash. 25系列是比较通用的一个系列. 后面的数字 16 跟容量有关, 16 表示 16Mbits, 相当于 2MB. 与此类似的还有 W25Q128V ...

  4. Oracle核心技术 笔记(该书读得不细致,须要找时间再细读~~)

    Oracle核心技术 跳转至: 导航. 搜索 文件夹 1 開始 2 redo和undo 3 事务与一致性 4 锁与闩 5 缓存和复制 6 写入和恢复 7 解析与优化 8 RAC及'缺陷' 9 附录A ...

  5. Chrome浏览器V43版本号不支持silverlight 5.0的解决的方法

    场景: 浏览器:chrome V43 插件:silverlight 5.0 操作系统:xp 问题: 自己开发silverlight站点在IE7和firefox中能正常打开,但在chrome中打开失败. ...

  6. leetcode笔记:Pascal&#39;s Triangle

    一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...

  7. 通过命令打包apk

    平时使用android studio打包,方便快捷,对命令不太熟悉,但在上传apk包到应用市场时,需要认领apk,“认领页的[选择APK]”不是上传您要更新的APK应用文件,而是下载我们提供的空包文件 ...

  8. 如何去除Office Excel的密码保护?

    企图更改Excel文件内容,然而却弹出如下提示: 根据提示,我尝试解除保护表,却要求输入密码: 这就尴尬了=_=密码不是我设定的 问了度娘,找到了解决方案 将Excel文件扩展名更改为rar, 使用压 ...

  9. sql server中like无法匹配下划线问题解决方案

    在sql server的like中下划线类似于通配符%,所以无法使用like '%_%'来匹配下划线,可以通过以下两种办法实现匹配下划线 1.使用转义字符escape like '%\_%' esca ...

  10. DEDE自定义表单显示提交时间|添加提交时间,获取ip的方法

    前提是后台自定义表单字段一定要有  “时间”,这里的acca_time <div class="tit">*咨询内容:</div> <div clas ...