CF-1114C-Trailing Loves (or L'oeufs?)
题意:
输入n和m,求n!转换成m进制之后末尾有多少个0;
思路:
转换一下题意就可以看成,将n表示成x * (m ^ y),求y的最大值。^表示次方而不是异或;
这就比较好想了,将m分解质因数,对于每个质因数,设n!含有a个,m含有b个,则ans = min(ans, a / b);
- 自己比赛的时候写的
C - Trailing Loves (or L'oeufs?) GNU C++11 Accepted 46 ms 0 KB #include "bits/stdc++.h"
using namespace std;
typedef long long LL;
map<LL, LL> mp, num;
vector<LL> vc;
int main() {
LL n, m;
scanf("%lld%lld", &n, &m);
for (LL i = ; i * i <= m; i++) {
if (m % i == ) {
vc.push_back(i);
while (m % i == ) {
m /= i;
mp[i]++;
}
}
}
if (m != ) {
vc.push_back(m);
mp[m]++;
}
for (int i = ; i < vc.size(); i++) {
LL j = ;
while (j <= n / vc[i]) {
j *= vc[i];
num[vc[i]] += n / j;
}
}
LL ans = 1LL << ;
for (LL i = ; i < vc.size(); i++) {
ans = min(ans, num[vc[i]] / mp[vc[i]]);
}
printf("%lld\n", ans);
return ;
}其实没必要把各个因子保存下来。标程还是优很多的
- 看了标程之后改的
C - Trailing Loves (or L'oeufs?) GNU C++11 Accepted 31 ms 0 KB #include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL INF = 1LL << ;
int main() {
LL n, m, ans = INF;
scanf("%lld%lld", &n, &m);
for (LL i = ; i <= m; i++) {
if (i * i > m) {
i = m;
}
if (m % i == ) {
int cnt = ;
while (m % i == ) {
m /= i;
cnt++;
}
LL tmp = , mul = ;
/*
for (LL mul = i; mul <= n; mul *= i)
这种写法应该更符合正常思维,但是因为n最高可以达到1e18,比较接近LL上限,mul可能乘i之前还小于n,乘完就爆LL了;
*/
while (mul <= n / i) {
mul *= i;
tmp += n / mul;
}
ans = min(ans, tmp / cnt);
}
}
printf("%lld\n", ans);
return ;
}
CF-1114C-Trailing Loves (or L'oeufs?)的更多相关文章
- Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论
https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...
- CF 1114 C. Trailing Loves (or L'oeufs?)
C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...
- 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 ...
- 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 ...
- CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数
题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...
- Trailing Loves (or L'oeufs?)
The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...
- 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 ...
随机推荐
- Json返回结果为null属性不显示解决
import java.io.IOException; import org.springframework.boot.autoconfigure.condition.ConditionalOnMis ...
- h5-钟表动画案例
1.html代码 <div class="clock"> <div class="line line1"> <div class= ...
- Android 公告新闻消息资讯之垂直滚动效果
垂直滚动新闻栏的实现原理: 就是一个自定义的LinearLayout,并且textView能够循环垂直滚动,而且条目可以点击,显示区域最多显示2个条目,并且还有交替的属性垂直移动的动画效果,通过线程来 ...
- php速成_day2
一.PHP中的多维数组 1.多维数组及其用途 多维数组用来存储多个元素,元素是一个数组的结构. 之前学习的数组,是一个一维数组. $person = array( 'name' => 'xiao ...
- share团队冲刺5
团队冲刺第五天 昨天:按钮操作,自定义按钮及各种原件样式 今天:设置按钮按下效果,界面布局 问题:无
- 细说opcache
; opcache的开关,关闭时代码不再优化. opcache.enable=1 ; Determines if Zend OPCache is enabled for the CLI version ...
- 题解 P2382 【化学分子式】
题目 不懂为什么,本蒟蒻用在线算法打就一直炸...... 直到用了"半离线"算法...... 一遍就过了好吗...... 某位机房的小伙伴一遍就过了 另一位机房的小伙伴也是每次都爆 ...
- 干货 | 京东云应用负载均衡(ALB)多功能实操
应用负载均衡(Application Load Balancer,简称ALB)是京东云自主研发的一款七层负载均衡产品,主要面向HTTP和HTTPS流量的WEB应用程序,提供灵活的功能配置.应用负载均衡 ...
- PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
- Codeforces Round #563 (Div. 2) 划水记
网太卡只好做划水选手,只做EF. E 很容易发现第一个数是2k或者是3*2k-1,因为消去因子次数要尽可能多,然后可以直接dp一发转移还剩几个2/3即可,写起来有些麻烦 #include<bit ...