Saturday, June 30, 2018

M00PAIR - 0 0 Pairs : Classical

#The solution in Python 3 is as follows:


import sys
A = [0, 1]
for _ in range(1000):
A.append(2*A[-2] + A[-1])
for ns in sys.stdin:
print(A[int(ns)-1])


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!



Thursday, June 28, 2018

CANDY - Candy I : Classical

#The solution in Python 3 is as follows:


while True:
n = int(input())
if n == -1: break
A = [int(input()) for _ in range(n)]
s = sum(A)
if s%n:                    #check if the candies can be distributed equally
print(-1)       
else:
print(sum(abs(s//n-a) for a in A)//2)


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

Wednesday, June 27, 2018

TWOSQRS - Two squares or not two squares : Classical

#The solution in Python 3 is as follows:

def check(n):
   i=2
   while i*i<=n:
       count=0
       if n%i==0:
           while n%i==0:
               count+=1
               n//=i
           if i%4==3 and count%2!=0:
               return False
       i+=1
   return n%4!=3
for _ in range(int(input())):
    n=int(input())
    if (check(n)):
        print("Yes")
    else:
        print("No")

#Visit this link for detailed explanation

#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

SNGPG - Prime Generator The Easiest Question Ever : Classical

#The solution in Python 3 is as follows:

for _ in range(int(input())):
a, b = map(int, input().split())
if a < 4:
print (min(3,b)-a+1)            #Just observe the output pattern
else:
print(0)


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

Monday, June 25, 2018

LASTDIG - The last digit : Classical

#The solution in Python 3 is as follows:

for _ in range(int(input())):
a, b = map(int, input().split())
print (pow(a, b, 10))                                   #((a^b)%10)


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

Sunday, June 24, 2018

ACPC10A - What’s Next : Classical

#The solution in Python 3 is as follows:

import sys
while 1:
    a, b, c = map(int,sys.stdin.readline().split())
    if a == 0 and b == 0 and c == 0:
        break
    elif b - a == c - b:
        print ("AP", c + (b - a))               #next term for AP sequences
    elif b/a == c/b:
        print ("GP", c * (b//a))                #next term for GP sequences


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

CODCHESS - Naya Shatranj (New Chess) : Classical

#The solution in Python 3 is as follows:

for _ in range(int(input())): print (1 - (int(input())%2))


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!