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. HDU 4857 topological_sort

    逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  2. CodeForces 321A Ciel and Robot(数学模拟)

    题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...

  3. weex 项目 创建 远程 icon

    一.创建 远程 icon 步骤一:打开  阿里巴巴矢量图标库 官网:http://www.iconfont.cn/ 步骤二:选择项目需要的 icon 步骤三:添加到项目(没有项目会自动创建) 步骤四: ...

  4. getElementByID,getElementsByName,getElementsByTagName

    <input type="checkbox" name="hobby" id="hobby1"> 音乐 <input ty ...

  5. oracle死锁解决经常用法(屡试不爽)

    --1.查询被锁的情况 select object_name,machine,s.sid,s.serial# from v$locked_object l,dba_objects o ,v$sessi ...

  6. 民大OJ 1668 追杀系列第二发

    追杀系列第二发 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte 总提交 : 57            测试通过 : 16 ...

  7. 未来 5 年八大热门 IT 职业

    近日.外媒梳理了未来5年内.也是就是2020年仍将受到热捧的八大科技领域,为IT从业者怎样做好长远规划.有针对性地培养自身技能.又不偏离热门岗位提供了參考. (图片来自网易) 2020年将热门的8大I ...

  8. postgres源码目录结构

    1.第一级目录介绍 |_postgres |_aclocal.m4------------config用的文件的一部分 |_config----------------config文件目录 |_con ...

  9. GuozhongCrawler系列教程 (5) TransactionRequest具体解释

    为了实现和维护并发抓取的属性信息提供线程安全的事务请求.TransactionRequest是一个抽象类自己不能设置Processor,却须要实现 TransactionCallBack接口.Tran ...

  10. 完美解决android显示gif

    今天是周5啊.纠结了一天.android显示gif,没该控件 网上找开源项目 找到个viewgif.该作者在各大站点都在推荐自己的项目...好吧.用下吧. . . . 结果呢: 图片略微一大就 内存溢 ...