Monday, September 13, 2010

Anagrams

Find all anagrams from a dictionary.

Anagram of a word is another word that is just rearrange of the letters of first word-

pots, stop, tops are anagrams of each other.

Rotation of a string

We have a string "ABCDEFGH". Write a program that rotates the string to make it "DEFGHABC". We have rotated the string by 3. You can not use any extra space except a few constant length primitive ones.

Wednesday, September 1, 2010

What is the base of a number

Problem Description

We use letters (A-Z) and digits (0-9) to represent a number. For example A0 in hexadecimal number is equal to 160 in decimal number and 240 in octal number. Given 2 numbers which are equal in two different base and given base of one number you have to find out base of another number.

Input

Three words in each line separated by spaces: first word is first number and second word is base of first number in decimal and third word is a number that is equal to first number for some different base. Letters will be capital always.

Output


Print out the base of second number in decimal and zero if can not find any base that is 2-36.

Sample input

A0 16 160
160 10 240

Sample Output

10
8

Monday, August 30, 2010

The first problem

Problem Description

Write a program that takes two integer numbers and find the distance between them.

Input


Sequence of two numbers that fits in 4 byte integer in a computer in each line separated by whitespace character.

Output


Distance between each pair in each line.


Sample input

1 2
5 7

Sample Output

1
2