码迷,mamicode.com
首页 > 其他好文 > 详细

实验吧 手脑并用

时间:2017-10-21 18:57:24      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:tar   pytho   blank   用户输入   nbsp   col   正数   for   factor   

手脑并用

 

对N!进行数学分析

解题链接: http://ctf5.shiyanbar.com/ppc/1.txt

 

求6789!的值末尾有几个零?

 

解题思路:

好吧,这感觉是一道送分题,求6789的阶乘

因为网上这个算法很多呀,求出这个阶乘复制一下后面的0,然后求和就可以了。

 

#!/usr/bin/python3
 
# Filename : test.py
# author by : www.runoob.com
 
# 通过用户输入数字计算阶乘
 
# 获取用户输入的数字
num = 6789
factorial = 1
 
# 查看数字是负数,0 或 正数
if num < 0:
   print("抱歉,负数没有阶乘")
elif num == 0:
   print("0 的阶乘为 1")
else:
   for i in range(1,num + 1):
       factorial = factorial*i
   # print("%d 的阶乘为 %d" %(num,factorial))

string = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
print(len(string))

 

实验吧 手脑并用

标签:tar   pytho   blank   用户输入   nbsp   col   正数   for   factor   

原文地址:http://www.cnblogs.com/zhaijiahui/p/7705371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!