Luo Gu P2388 factorial of multiplication problem solution

This Konjac again made the explanations QwQ;

See this topic, the first thing you want to write konjac make violence;

Ah, the bad habits;

However, with half a brain think you know, ordinary violence can not be over;

However, as konjac, I could not think what to optimize advanced mathematical methods;

Well, back to the topic

Entitled asked us to find this tired at the end of the ride '0'

'0' is a particularly special number, because that multiplies, then a '0' must be '2' one by one and '5' by multiplying come;

Also the number of '0' must be between '2' and '5' that a smaller number of the number;

And we are also seeking its factorial multiplicative,

Therefore, the number '5' must be less than '2' number

Then the number of '0' is' 5 'the number'

This well written;

. PS We have enough time to write this question, then you run 100ms off 100 points, 1ms also had 100 points; then we should not be blind to the pursuit of faster, more advanced methods, should more effective practice (crossed out; but I think it can be more time to think about it, you can exercise workout thinking.

This represents only personal point of view;

Good, happy time code:

#include<bits/stdc++.h>
using namespace std; #define int long long//不开long long见祖先 int n, now, num, ans;//num是这一轮的‘0’的个数,ans是总答案; signed main() { scanf("%lld", &n);//输入 for(int i = 1; i <= n; ++ i)//累乘,依次枚举 { now = i;//因为要不断除5,所以不可以直接用i; while(now % 5 == 0)//找‘5’ { ++ num;//加一个 now /= 5;//除上5 } ans += num;//相加 //注意:num不需要赋值为0,也不可以 //因为它的累乘包含了它的前面的点, //所以如果num赋值为0后就会导致错误 } printf("%lld", ans);//输出,再次强调一定要开long long return 0; }

Guess you like

Origin www.cnblogs.com/Flash-plus/p/11210698.html