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. 转: memcache, redis, mongodb 对比

    http://db-engines.com/en/system/Memcached%3BMongoDB%3BRedis

  2. 使用UltraISO刻录自己的音乐CD步骤

    1.文件->新建->音乐光盘映像. 2.在左下方,“本地目录”中,找到音乐所在目录,右下方会出现mp3等音乐文件. 3.在右下方,点击音乐文件,右键选“添加”.音乐文件会出现在右上方窗口里 ...

  3. Solidedge如何修改特征的参数

    我已经长出了60MM,现在发现不对,要改成50MM.右击这个特征,点击编辑定义   直接左键单击尺寸,修改数据,按回车,鼠标右键,即可.    

  4. shell mysql 直接创建表

    shell 直接创建表 #!/bin/bash mysql -hdatabases -uroot -p^xxxxasdasdadd <<EOF Create Database If Not ...

  5. 【C语言天天练(九)】动态内存分配

    引言:数组的元素存储于内存中连续的位置上.当一个数组被声明时.它所须要的内存在编译时就被分配. 可是,我们能够使用动态内存分配在执行时为它分配内存. 一块内存的生命周期能够分为四个阶段:分配.初始化. ...

  6. Eclipse中Easy Shell插件配置PowerCmd

    1.了解EasyShell.PowerCMD和基本命令 http://sourceforge.net/projects/pluginbox/ http://www.powercmd.com/ 了解基本 ...

  7. 继承LinearLayout实现根据屏幕宽度及内部子View个数自动排布GridView

    public class VerticalSearchGridView extends LinearLayout implements View.OnClickListener { private i ...

  8. Android SDK更新失败的解决方案(原创)

    笔者在搭建好Android环境后,进行Android的SDK更新下载升级,乌龟的速度,更让人生气的是到了85%的进度时,直接timeout,循环3次无果.查阅相关资料,原来是Google的服务器遭遇了 ...

  9. 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决的方法

    今天在使用android studio在Genymotion上调试程序出现INSTALL_FAILED_CPU_ABI_INCOMPATIBLE导致程序安装不了: 后来百度发现是要安装:http:// ...

  10. Codeforces Round #422 (Div. 2) D. My pretty girl Noora 数学

    D. My pretty girl Noora     In Pavlopolis University where Noora studies it was decided to hold beau ...