Delivered Ali's C + + direction research and development, participate in the online written test completely ignorant, a variety of math problems, puzzles, and a variety of seemingly irrelevant topics together, you feel under.
The problem is related to the basic mathematical problems of permutation and combination. The following section on the above topics to give their own opinions, if there is wrong place, I hope you correct.
About the number of n! how many 0
Idea: Given an integer n, then the factorial n of n! How many of the 0 problems at the end can be converted to the problem of how many 5 can be decomposed in the n! multiplicative. Because 5 and any of the even numbers in front of it will produce 0, it is only necessary to divide the number of 1 from 5 to N. For example 25! , can be decomposed 5 (1x5), ten (2x5), (3x5), (4x5) (5x5), a total of 6 5 can be decomposed, so 25! At the end there are 6 0;
This can infer 15! Finally there are 3 of 0 ...
Of course, special circumstances need to pay attention to, such as the number is 100,1000 such a situation, there are 50,500 such circumstances, the landlord a little thought is not difficult to draw the right conclusion.
For example 10! =10X9X8X7X6X5X4X3X2X1=2X5X9X8X7X6X5X4X3X2X1 (contains 2 5, so there are two 0 at the end of the result)
/* name:n!. CPP copyright:52coder.net Author:HeHe.wang date:03-04-15 10:58 Description: Program user OK n! ( n the factorial result of how many 0) */#include <stdio.h>int zeronum (int n) { int j,num=0; for (int i=n;i>1;i--) { j=i; while (j%5==0) { num++; j/=5; } } return num;} int main () { int n=100; printf ("%d", Zeronum (n));}
question two: any one of 0-999999 does not contain the number of numbers 1:
See this problem the first time I was in Baidu, Google, but no one found, I think now if the words in Baidu should be found.
at first I wrote the following procedure to find that any one of 0-999999 does not contain the number of numbers 1
My idea is to find out that 0-999999 contains 1 of the number, and then 999999 minus the number containing 1
because the calculation is from 0-999999, so the last calculation is N+1-count
actually, it's simpler to use permutations and combinations 9x9x9x9x9x9=531441
#include <stdio.h> int count (int n) { while (n!=0) { if (n%10==1) return 1; n/=10; } return 0;} int main () { int icount=0; int n; scanf ("%d", &n); for (int i=0;i<=n;i++) { icount+=count (i); } printf ("%d\n", N+1-icount);}
the rest of the arrangement of a few questions relatively simple, real test C + + problems, I actually did not expect to copy the code into the compiler run again, but their own operations, I was too simple ah.Welcome to the message discussion, pointing out the wrong place.
2015 Ali Research and Development Engineer Internship Test Choice question