zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    服务器安装软件
    SQL server
    改变下blog思维
    react 父子组件互相通信
    linux下,文件的权限和数字对应关系详解
    Linux 下非root用户使用docker
    Two 观察者 observer pattern
    one 策略模式 strategy
    ssm maven spring AOP读写分离
    Unknown column in 'where clause'
  • 原文地址:https://www.cnblogs.com/martian148/p/15390522.html
Copyright © 2011-2022 走看看