Sunday, July 28, 2013

15388 Easy One For Cartman

Easy One For Cartman

CODE
import math
t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    a=int(str[0])
    b=int(str[1])
    n=int(str[2])
    d=b-a
    ans=n*(2*a+(n-1)*d)/2
    #ans=(pow(n%1000000007,r%1000000007))%1000000007
    print ans

TRAINGLE

TRYANGLE
CODE

import math
t=int(input())
for i in range(1,t+1):
    n=int(input())
    ans=(n*(n-1)*(n-2))/6
    print "Case %d: %d" % (i,ans)
Counting Ids
CODE

import math
while(True):
    s=raw_input()
    str=s.split(' ')
    n=int(str[0])
    r=int(str[1])
    if(n==0 & r==0):
        break;
    else:
        ans=(n*(pow(n,r)-1)/(n-1))%1000000007
        print (ans)