cf1114 C. Trailing Loves (or L'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;
    scanf("%lld%lld",&n,&x);
    if(n==1)
    {
        printf("0\n");
        return 0;
    }
    int m=0;
    for(int i=2;1LL*i*i<=x;i++)//一旦出现大于10^9的数字,所有变量(包括i,j都要用long long),惨痛的教训
    {
        printf("%d\n",i);
        if(x%i==0){
            p[++m]=i,c[m]=0;
            while(x%i==0) x/=i,c[m]++;
        }
    }
    if(x>1) p[++m]=x,c[m]=1;
    int tot=0;
    //printf("***\n");
    for(int i=1;i<=m;i++)
    {
        ll tmpn=n;
        ll num=0;
        //printf("****\n");
        while(tmpn)
        {
            //printf("%d\n",++tot);
            num+=tmpn/p[i];
            tmpn/=p[i];
        }
        num/=c[i];
        res=min(num,res);
    }
    printf("%lld\n",res);
}

cf1114 C. Trailing Loves (or L'oeufs?)

原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10361154.html

时间: 2024-08-02 22:44:27

cf1114 C. Trailing Loves (or L'oeufs?)的相关文章

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) *

【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; } [代码

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(

Trailing Loves (or L&#39;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

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

CF-1114 (2019/02/11)

CF-1114 A. Got Any Grapes? skip B. Yet Another Array Partitioning Task 将n个数分成连续的k组,使得每组的前m大的数字的总和最大. 首先可以想到肯定可以包含n个数中前 m*k 大的数.所以可以先将他们标记,然后扫一遍确定每组的端点即可 #include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,k; struct node{ int

Codeforces Round #538 (Div. 2) (CF1114)

Codeforces Round #538 (Div. 2) (CF1114) ??今天昨天晚上的cf打的非常惨(仅代表淮中最低水平 ??先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O(n^2)的线性dp,然后就wa6,调到结束.结束后发现完全看漏了两句话.噢,起始点!!! ??好吧然后算算自己有可能这一场要变成+0,反正在0左右. 结束后开始然后开始写D,顺便思考F.结果写完D发现A怎么fst了,然后...因为习惯于对相似的语句复制粘贴,有些东西没有改--三句话都在 -a!!!(

CF每日一练(2.11)

CF-1114 A. Got Any Grapes? skip B. Yet Another Array Partitioning Task 将n个数分成连续的k组,使得每组的前m大的数字的总和最大. 首先可以想到肯定可以包含n个数中前 m*k 大的数.所以可以先将他们标记,然后扫一遍确定每组的端点即可 #include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,k; struct node{ int

CodeForces Contest #1114: Round #538 (Div. 2)

比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄至少 \(b\) 个,第三个人需要吃绿色.紫色和黑色葡萄至少 \(c\) 个. 有 \(x\) 个绿色葡萄,\(y\) 个紫色葡萄,\(z\) 个黑色葡萄,问是否能够满足三个人的要求. 题解: #include <cstdio> int main() { int x, y, z, a, b, c;