Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论
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?) - 简单数论的更多相关文章
- 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 ...
- CF 1114 C. Trailing Loves (or L'oeufs?)
C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...
- C. Trailing Loves (or L'oeufs?) (质因数分解)
C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...
- Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)
大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...
- 【Codeforces 1114C】Trailing Loves (or L'oeufs?)
[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...
- 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 ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...
- Trailing Loves (or L'oeufs?)
The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...
- Codeforces1114C Trailing Loves (or L'oeufs?)
链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...
随机推荐
- 小程序 - Template
关于模板,参见:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/template.html 引入模块 <import ...
- java开始到熟悉63-65
本次内容:java常用类 1.包装类 package array; public class wrapperclass { public static void main(String[] args) ...
- 网页JS简繁体字转换
用法:非得加上html头 utf-8编码 其它编码无测试 head 中引用 <script language='javascript' src='zh.js'></script> ...
- ASI和AFN实现POST异步请求的相同功能的代码
I'm a newbie in obj-c and have been using asihttp for some of my projects. When doing a post request ...
- cocoapods导入框架出错 The dependency `FMDB` is not used in any concrete target
问题描述: The dependency `FMDB` is not used in any concrete target 解决办法: 官网是这样给推荐的: 在创建Podfile的时候,用这种格式使 ...
- V-Play 文档翻译 Page
V-Play 文档翻译 Page 翻译:qyvlik 应用的一个页面. VPlayApps 1.0 Inherits: MouseArea Inherited By: ListPage 属性 Item ...
- CentOS笔记-vim
详细的参考http://www.runoob.com/linux/linux-vim.html i插入 I 行首插入 A 行尾插入 fn + ←,行首 fn + →,行尾 fn + ↑,向上翻页 fn ...
- MongoDB Spark Connector
[在文件/usr/bin/yum./usr/libexec/urlgrabber-ext-down最上面的一行改为#!/usr/bin/python2.7] yum install git Note: ...
- 文件批量转换成UTf-8
yum install -y enca 在文件夹根目录下面创建文件:iconv_shell.sh 里面填写下面的内容: #!/bin/bash for file in `find ./ -name ' ...
- 分析PHP的include机制
php在解析include指令时,会对包含的文件路径做如下判断: 如果是绝对路径,则直接包含,并结束. 如果是相对路径,则做如下判断: 相对路径以特殊符号开头,如 "./1.php" ...