Small factorials Solved Problem code: FCTRL2

 1 import sys
 2
 3
 4 def fact(n):
 5     final = n
 6     while n > 1:
 7         final *= n - 1
 8         n -= 1
 9     return final #逻辑严谨,不要忘了return
10
11
12 def main():
13     t = int(sys.stdin.readline())
14     for n in sys.stdin:
15         print fact(int(n)) #读取String的转换是一个常见的坑
16
17
18 main()

//第二种,利用现成的库

 1 from math import factorial #熟悉这种调用方法
 2
 3
 4 def main():
 5     t = int(raw_input())
 6     for i in range(t):
 7         print factorial(int(raw_input()))
 8
 9
10 main()

学习

  怎么调用外部的库  

错误

  函数忘了return, 思路不严谨

  读取时候忘了类型转换

    py的类型转化更为注意,比起有类型规定的C

时间: 2024-09-30 13:03:53

Small factorials Solved Problem code: FCTRL2的相关文章

ATM Solved Problem code: HS08TES

1 # ATM 2 import sys 3 4 withdraw, balance = map(float, sys.stdin.readline().strip().split()) # strip()用法去除结尾的\n符号 5 6 if int(withdraw) % 5 != 0 or balance < (withdraw + 0.5): # 1.注意手续费,缺少手续费也不能取 2.xy0~2000是测试值要求,不用判断 7 print("%.2f" % balance

Enormous Input Test Solved Problem code: INTEST

import sys import psyco #一键优化库 psyco.full() def main(): n, k = map(int, sys.stdin.readline().strip().split()) #两位数输入的复用 count = 0 for t in sys.stdin: #注意这个for循环方式 if int(t) % k == 0: count += 1 print '%d' % count #注意格式输出 main() #写成函数的格式是一个良好的习惯 学到 py

Factorial Solved Problem code: FCTRL

1 import sys 2 #import psyco #很奇怪,这题用psyco就runtime error 3 4 5 #psyco.full() 6 7 8 def z(n): #这个应该是技巧的一种算法 9 r = 0 10 while 5 <= n: 11 n /= 5 12 r += n 13 return r 14 15 16 def main(): 17 n = int(sys.stdin.readline()) 18 for t in sys.stdin: #这种循环输入一点

Chef and Prime Divisors Problem code: CHAPD (GCD问题)

题目大意: 给定两个数,n,m,找到如果m的所有质因数可以被n,整处的话输出"Yes",OR   "No". text: 3 120 75 128 16 7 8 Output: Yes Yes No 直到,最大公约数为1,时看后者是否为1,即可. #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<c

Turbo Sort Add problem to Todo list Problem code: TSORT

1 def heap_sort(ary): 2 n = len(ary) # 8 3 first = int(n / 2 - 1) # 3 4 for start in range(first, -1, -1): # 3~0 revese 5 max_heapify(ary, start, n - 1) # from start 6 for end in range(n - 1, 0, -1): 7 ary[end], ary[0] = ary[0], ary[end] 8 max_heapif

Holes in the text Add problem to Todo list Problem code: HOLES

1 import sys 2 3 4 def count_holes(letter): 5 hole_2 = ['A', 'D', 'O', 'P', 'Q', 'R'] 6 if letter == 'B': 7 return 2 8 elif letter in hole_2: 9 return 1 10 else: 11 return 0 12 13 14 def main(): 15 n = int(sys.stdin.readline()) 16 for t in sys.stdin:

The Lead Game Add problem to Todo list Problem code: TLG

1 '''def count_lead(first, second): 2 if first > second: 3 return 1, first - second 4 elif first == second: # 题目中没有说明相等的情况 5 return 0, 0 6 else: 7 return 2, second - first''' 8 9 10 def main(): 11 n = int(raw_input()) 12 lead = 0 13 winner = 0 # 有些初始

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

Use Spring Insight Developer to Analyze Code, Install it with Tomcat, and Extend it with Plugins--转载

原文地址:http://www.tomcatexpert.com/blog/2012/12/05/use-spring-insight-developer-analyze-code-install-it-tomcat-and-extend-it-plugins People are still discovering the benefits of the free tool from VMware SpringSource, called Spring Insight Developer. T