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 ...
随机推荐
- Jupyter notebook 和 Jupyter lab 的区别
Jupyter Notebook Jupyter Notebook 是一个款以网页为基础的交互计算环境,可以创建Jupyter的文档,支持多种语言,包括Python, Julia, R等等.广泛用于数 ...
- Tensorflow学习教程------读取数据、建立网络、训练模型,小巧而完整的代码示例
紧接上篇Tensorflow学习教程------tfrecords数据格式生成与读取,本篇将数据读取.建立网络以及模型训练整理成一个小样例,完整代码如下. #coding:utf-8 import t ...
- 剑指offer【12】- 二进制中1的个数
输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. public class Solution { public int NumberOf1(int n) { String str = ...
- hdu 1246
很久没有写题解了~因为懒(年纪大了就是脸皮厚,还有脸说) 这道题今天花了很长时间去推,一开始以为是规律题,没推出来,直接模拟也TLE了,接着考虑实在是没思路,看了题解. 思路大概就是这样: 先上代码( ...
- goweb-go语言基础
go语言基础 虽然这本书是讲goweb,但还是吧go语言基础过了一遍,由于我之前已经对go语言基础做了一遍系统的学习,这里就当简单回顾一下,不再写过多笔记了,之前的写的博客都有基础知识,O(∩_∩)O ...
- apache 伪静态配置 .htaccess
htaccess语法教程apache服务器伪静态规则教程 虽然网上有很多教程,不过发现大部分都是抄袭一个人的,一点都不全,所以我想写一个简单的易于理解的教程,我学习.htaccess是从目录保护开始的 ...
- 通过TleChat插件一键Getshell
TleChat网站插件是一个发布到wordpress,typecho和emlog社区上的站长聊天插件,站长聊天室插件为站长和用户提供聊天室功能,让站长与用户之间的联系更加友爱,支持文本.长文本.语音聊 ...
- Python语言学习:pyc是什么
一.pyc 1.PyCodeObject:是python编译器真正编译成的结果 当python程序运行时,编译的结果是保存在位于内存中的PyCodeObject中.当python程序运行结束时,pyt ...
- 计量经济与时间序列_ADF单位根检验步骤
1 ADF检验也叫扩展的迪克富勒检验,主要作用是检测序列的平稳性,也是最常用检测序列平稳性的检验方法. 2 何为:平稳性?单位根?(略),见这部分随便的其他内容有讲解.是建模对数据的先决条件. 3 A ...
- How Cocoa Beans Grow And Are Harvested Into Chocolate
What is Cocoa Beans Do you like chocolate? Most people do. The smooth, brown candy is deliciously sw ...