Sunday, August 25, 2013

The last digit

LASTDIG
Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. You have to find the last digit of a^b.


CODE



import math
t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    a=int(str[0])
    b=int(str[1])
    if(b==0):
        print 1
    else:
        a=a%10
        b=b%4
        if(b==0):
            b=4
        print pow(a,b)%10
 

Kamil

KAMIL
Some kids cannot pronounce all letters, some of them they sometimes pronounce correctly and sometimes incorrectly. Kamil sometimes says T instead of K, but he never says K instead of T. Similarly he sometimes says D instead of G. Instead of R he sometimes says L and sometimes F. Of course it happens that he pronounces the letter correctly. Kamil's father always thinks how many words can mean the word spoken by his son (it doesn't matter if they are real English words).


code


for i in range(10):
    t=raw_input();
    print 2**sum(t.count(i)for i in'DFLT')


 

Friday, August 9, 2013

3932. Point Connection Game in a Circle


MCIRGAME/
CODE

def fac(n):
    if(n==0):
        return 1
    else:
        return n*fac(n-1)
while(True):
    k=input()
    if(k==-1):
        break
    else:
        temp=fac(2*k)/(fac(k+1)*fac(k))
        print temp


9952. 111…1 Squared

Problem code: GUANGGUN

CODE

import sys
for s in sys.stdin:
    n=int(s)
    if(n<10):
        print n*n
    else:
        t=(n-10)/9+1
        k=10+(t-1)*9
        ans=((81*t)+1)+((n-k)*(n-k+2))
        print ans

   

 

 UCV2013I

CODE

import math
while(True):
    s=raw_input()
    str=s.split(' ')
    r=int(str[0])
    n=int(str[1])
    if(n==0 & r==0):
        break;
    else:
        x=math.pi/2
        R=r/math.sin(x/n)
        print ("%.2f")%R