Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

大意: 求n!在b进制下末尾0的个数

等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了

ll n, b;
vector<pli> A, res;

void factor(ll x) {
    int mx = sqrt(x+0.5);
    REP(i,2,mx) if (x%i==0) {
        int t = 0;
        while (x%i==0) x/=i,++t;
        A.pb(pli(i,t));
    }
    if (x>1) A.pb(pli(x,1));
}

int main() {
    cin>>n>>b;
    factor(b);
    int sz = A.size();
    ll ans = 1e18;
    REP(i,0,sz-1) {
        ll t = 0, num = n/A[i].x;
        while (num) t+=num, num/=A[i].x;
        ans = min(ans, t/A[i].y);
    }
    printf("%lld\n", ans);
}

Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

原文地址:https://www.cnblogs.com/uid001/p/10507583.html

时间: 2024-08-02 22:43:54

Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)的相关文章

【Codeforces 1114C】Trailing Loves (or L&#39;oeufs?)

[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/81167283 这题的话m比较大, 做个质因数分解就ok>_< 算n!有多少个x因子的话 以5为例子 (n=25) 25 20 15 10 5 把他们都除5 5 4 3 2 1 然后再除5 1 所以总共有6个 转换成代码就是 while(n>0){ ans+=n/5; n = n/5; } [代码

CF#538 C - Trailing Loves (or L&#39;oeufs?) /// 分解质因数

题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10的幂的个数 即 1500=15*10^2 与两个0 在任意进制下也是 即n!在b进制下 n!=a*b^x 那么末尾0的个数就是 x 若b能分解出质因数 b1 b2 b3 ... 那么 a*b^x = a*(b1^x1 * b2^x2 * b3^x3 ... )^x = a*(b1^(x1*x) *

cf1114 C. Trailing Loves (or L&#39;oeufs?)

注意题目中一旦有大于1e9的数字,所有变量全用Longlong替代,包括i,j 或者一开始直接define int longlong ,然后之后主函数用int32_t,输入输出用int32_t替代 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF=1e18+7; ll p[1000010]; ll c[1000010]; ll res=INF; int main() { ll n,x;

C. Trailing Loves (or L&#39;oeufs?) (质因数分解)

C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行质因数分解后,每个因数个数的最小值 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; #define N 1000005 ll pri[N]; ll cnt[N]; ll tot; void getpri(

CF-1114C-Trailing Loves (or L&#39;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" usi

Codeforces 1114C(数论)

题面 传送门 分析 我们先考虑n!在10进制下有多少个0 由于10=2*5, 我们考虑n!的分解式中5的指数,答案显然等于\(\frac{n}{5}+\frac{n}{5^2}+\frac{n}{5^3}+\dots\frac{n}{5^k}(\frac{n}{5^k}\geq 1,\frac{n}{5^{k+1}}<1)\) 可以用一个递归函数来计算: ll f(ll x,ll y){ if(x<y) return 0; else return x/y+f(x/y,y); } 由于5的个数显

codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ...,

CodeForces 396A 数论 组合数学

题目:http://codeforces.com/contest/396/problem/A 好久没做数论的东西了,一个获取素数的预处理跟素因子分解写错了,哭瞎了,呵呵, 首先ai最大值为10^9,n为500,最坏的情况 m最大值为500个10^9相乘,肯定不能获取m了,首选每一个ai肯定是m的一个因子,然后能分解就把ai给分解素因子,这样全部的ai都分解了  就能得到m的 所有素因子 以及 所有素因子的个数,题目求的 是n个因子的 不同序列的个数,所以每次 只能选出n个因子,这n个因子由素因子

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is a