首页 > 其他分享 >poj-1401

poj-1401

时间:2023-05-23 16:03:51浏览次数:30  
标签:10 val res long caseNum poj 1401 lld


//408K  375MS   G++
#include <cstdio>
#include <cstring>

long long get2FactorNum(long long N) {
    long long res = 0;
    while(N) {
        res += N/2;
        N /= 2;
    }
    return res;
}

long long get5FactorNum(long long N) {
    long long res = 0;
    while(N) {
        res += N/5;
        N /= 5;
    }
    return res;
}

long long caseNum;
int main() {
    scanf("%lld", &caseNum);
    for (long long i = 0; i < caseNum; i++) {
        long long val;
        scanf("%lld", &val);
        long long Num1 = get2FactorNum(val);
        long long Num2 = get5FactorNum(val);
        long long res = Num1 > Num2 ? Num2: Num1;
        printf("%lld\n", res);
    }
}



用到了和3219一样的技法,

题目要求N!最后面0的个数,其实就是求在N<->1的范围内的乘数中,能拼出多少个10, 这个10必然就是最后那一串0之一,

即 N! = X*Y*..*Z*10*10*10...., (前面的X*Y*...Z不可能再拼出*10),而因为10在 因子<=9的情况下 只能是 2*5 == 10,

因此就求出在N!就多少个因子2(F1)和多少个因子5(F2)就可以,取其中最小值, 就是最后能拼出的*10的个数.



标签:10,val,res,long,caseNum,poj,1401,lld
From: https://blog.51cto.com/u_9420214/6332971

相关文章

  • poj-2231
    //264K 47MS C++#include<cstdio>#include<cstring>#include<cstdlib>constintMAX=10005;longlongcowLocation[10005];intcmp(constvoid*a,constvoid*b){ return*((longlong*)a)-*((longlong*)b);}longlongcowNum;......
  • poj-1308
    //392K0MSG++#include<cstdio>#include<cstring>usingnamespacestd;constintMAX=10000;intUF_set[MAX];voidUF_get_setId(intcurId){intparentId=UF_set[curId];if(parentId==0){return;}while(UF......
  • poj-1120
    //408K16MSG++#include<cstdio>#include<cstring>usingnamespacestd;intdish[20][20];intK[20][20];intD[16];intdays;intgetDensitySum(introwId,intcolumnId){intK=0;K+=dish[rowId][columnId];if(rowId......
  • poj-3641
    //712K0MSG++#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>usingnamespacestd;longlonga,p;//longlongpower2(longlonga,longlongn)//{//longlongret=1;//for(longlongm......
  • poj-1026
    //188K110MSC++#include<cstring>#include<cstdio>#include<iostream>usingnamespacestd;charstr1[205];charstr2[205];intkey[205];intcycleLength[205];//voidreplace(char*str,intkeyLength,intstrLength){//......
  • poj-2707
    //408K0MSG++#include<cstdio>#include<cstring>usingnamespacestd;intoX;intoY;intdX;intdY;inlinedoubleMIN(doublea,doubleb){returna<b?a:b;}inlinedoubleMAX(doublea,doubleb){returna>b?......
  • poj-2635
    //1652K875MSG++1000//1648K1313MSG++10000#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>constintMAX=1000100;charnotPrime[MAX+1];intPrimeNum;intPrimes[MAX];voidcheckPrim......
  • poj-3286
    //stupidmethod!!!!!!!!!!!!!!!//388K360MSG++#include<stdio.h>#include<string.h>#include<math.h>intC[33][33];//C[n][m],choosemfromn;voidgetCombination(){for(intn=0;n<=32;n++){for(intm=......
  • poj-2282
    //380K 32MS G++#include<stdio.h>#include<string.h>#include<math.h>longlongappearTime1[10];longlongappearTime2[10];voidgetAppearTime(intnum,longlong*appearArray){ appearArray[0]=1; if(num==0){ return; }......
  • poj-2249
    //356K16MSG++//356K0MSG++addm==0check//356K16MSG++//356K0MSG++addm==0check#include<stdio.h>#include<string.h>#include<math.h>intm;intn;//voidgetNum(unsignedintn,unsignedintm){//......