• P3992 [BJOI2017]开车


    题面描述

    P2388 阶乘之乘

    (1! imes 2! imes 3! imes ... imes n!) 末尾 (0) 的个数

    题解

    其实原题的数据范围不大,(n≤1e8) 但给了我很多思考

    (F(i)= sum_{i=1}^{infty}leftlfloordfrac{n}{5^i} ight floor)

    [ans=sum_{i=1}^{n} F(i)= sum_{i=1}^{n}sum_{j=1}^{infty}leftlfloordfrac{n}{5^i} ight floor=sum_{j=1}^{infty}sum_{i=1}^{n}leftlfloordfrac{n}{5^i} ight floor=sum_{j=1}^{infty}(5^j imes sum_{i=1}^{lfloorfrac{n}{5^i} floor-1}i+ lfloorfrac{n}{5^i} floor imes(n\%^j+1)) ]

    柿子有点长

    代码实现

    #include<bits/stdc++.h>
    using namespace std;
    long long N,ans;
    struct IO{
        static const int S=1<<21;
        char buf[S],*p1,*p2;int st[105],Top;
        ~IO(){clear();}
        inline void clear(){fwrite(buf,1,Top,stdout);Top=0;}
        inline void pc(const char c){Top==S&&(clear(),0);buf[Top++]=c;}
        inline char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
        inline IO&operator >> (char&x){while(x=gc(),x==' '||x=='
    '||x=='r');return *this;}
        template<typename T>inline IO&operator >> (T&x){
            x=0;bool f=0;char ch=gc();
            while(ch<'0'||ch>'9'){if(ch=='-') f^=1;ch=gc();}
            while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=gc();
            f?x=-x:0;return *this;
        }
        inline IO&operator << (const char c){pc(c);return *this;}
        template<typename T>inline IO&operator << (T x){
            if(x<0) pc('-'),x=-x;
            do{st[++st[0]]=x%10,x/=10;}while(x);
            while(st[0]) pc('0'+st[st[0]--]);return *this;
        }
    }fin,fout;
    int main(){
    	fin>>N;
    	for(int j=5;j<=N;j*=5){
    		ans+=j*(N/j)*(N/j-1)>>1;
    		ans+=(N/j)*(N%j+1);
    	}
    	fout<<ans;
    	return 0;
    }
    
  • 相关阅读:
    安装 kubenetes-dashboard
    使用kubeadm在Centos7上部署kubernetes1.21.1
    批量重命名
    is_valid重写。返回数据格式统一
    django-序列化参数为空报错问题
    单文件日志测试
    文本、目录 空间清理问题
    数仓数据
    滑动验证码(无原图片处理)
    鸟哥私房菜基础篇
  • 原文地址:https://www.cnblogs.com/martian148/p/15390522.html
Copyright © 2020-2023  润新知