Pages

Bangladeshi Blog
Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Friday, January 14, 2011

24. Small Factorials

code:
def f(n):
    if n == 0:
        return 1
    else:
        return n * f(n-1)

for t in range(0, input()):
    print "%d" % f(input())

# end of source code
Be Pythonic

8060. Cookies Piles

code:
tc = int(input()) 

while tc: 
    tc -= 1 
    n, a, d = [int(x) for x in raw_input().split()] 
    total = 0 
    while n: 
        n -= 1 
        total += a 
        a += d 

    print total

# end of source code
Be Pythonic

7974. What's Next

code:
while 1: 
    a, b, c = [int(x) for x in raw_input().split()] 
    if a == 0 and b == 0 and c == 0: 
        break 

    elif b - a == c - b: 
        print 'AP', c + (b - a) 
         
    elif b/a == c/b: 
        print 'GP', c * (b/a)

# end of source code
Be Pythonic

302. Count on Cantor

code:
import math 

tc = int(raw_input()) 

while tc: 
    tc -= 1 
    term = int(raw_input()) 
    row_p = float((-1 + (1 + 8 * term) ** 0.5) / 2.0) 
    row = int(math.ceil(row_p)) 

    pos = term - (row * (row - 1)) / 2; 

    a = row - pos + 1 

    if row % 2 == 0: 
        print 'TERM %d IS %d/%d' % (term, pos, a) 

    else: 
        print 'TERM %d IS %d/%d' % (term, a, pos)
Be Pythonic