Bulgarian OI '09 P5 - Special Sequence

View as PDF

Submit solution


Points: 30 (partial)
Time limit: 0.6s
Memory limit: 32M

Problem type
2009 Bulgarian Olympiad in Informatics

Consider the positive integers whose squares contain only (and all) the digits 0,4,9. Let's call them "special". For example, 2120 is special, because 21202=4494400 and the square contains only (and all) of 0,4,9. 97 is also special: 972=9409. 13 and 7 are not special - 132=169 (1 and 6 aren't allowed) and 72=49 (there's no 0).

Consider the sequence of special numbers, in order:

{70,97,700,970,997,2120,3148,7000,9700,9970,9997,20102,21200,31480,70000,97000,}

Write a program to find the Nth number in this sequence.

Input Specification

The positive integer N250, on a single line.

Output Specification

The Nth number in the special sequence (starting from 1).

Sample Input

Copy
12

Sample Output

Copy
20102

Comments

There are no comments at the moment.