现在的位置: 首页 > 综合 > 正文

2.2阶乘末尾0的个数,最低位1的位置

2013年02月23日 ⁄ 综合 ⁄ 共 441字 ⁄ 字号 评论关闭

0的个数

 1 #include <iostream>
2 using namespace std;
3
4 #include <stdlib.h>
5 #include <sys/types.h>
6
7 int Count(int n)
8 {
9 int count = 0;
10 while (n) {
11 count += n / 5;
12 n /= 5;
13 }
14 return count;
15 }
16
17 int main()
18 {
19 cout << Count(26) << endl;
20
21 return 0;
22 }

1的位置

 1 #include <iostream>
2 using namespace std;
3
4 #include <stdlib.h>
5 #include <sys/types.h>
6
7 int Count(int n)
8 {
9 int count = 0;
10 while (n) {
11 count += n / 2;
12 n /= 2;
13 }
14 return count + 1;
15 }
16
17 int main()
18 {
19 cout << Count(4) << endl;
20
21 return 0;
22 }

抱歉!评论已关闭.