NYOJ56 阶乘因式分解(一)
思路:比如说13的阶乘中有多少个3.
13!=1*2*3*...*6*...9*...12;
其中有多少个数能被3整除呢?答案是13/3=4个。
但是答案却是5,为什么,因为9里面有2个3所以是4个.
若是100!里面有多少个5?首先看里面有多少个数能被5整除,答案是100/5=20;
再看有多少个数能被5*5整除,答案是100/25=(100/5)上面的结果/5,直到除到结果小于5为止,把每个式子的结果相加即为答案。
#include <stdio.h> int main(){ int t, a, b, count; scanf("%d", &t); while(t--){ scanf("%d%d", &a, &b); count = 0; while(a >= b){ count += a / b; a /= b; } printf("%d\n", count); } return 0; }