This page is still under construction.

Parts of this page are still being built. What you see may change.

Sevens, Twos and Zeros

Time limit1sMemory limit128 MB

Summary
Find the smallest multiple of n that is at least n, uses only digits 7, 2, 0, and has at most 20 digits, or report NAV.
Level

Hard8 of 10

Topics
BFS, Dynamic programming, Math, Brute force
Solved
No attempts yet

Problem

Given a natural number nn, write a program that outputs the smallest number ss satisfying all of the following conditions.

  • s≥ns \ge n;
  • written in decimal, ss consists only of the digits 7, 2 and 0, and does not start with 0;
  • the decimal representation of ss has at most 20 digits;
  • ss divided by nn leaves a remainder of 0.

Input

A single natural number nn (0<n<5000000 < n < 500000) is given on one line.

Output

Output the number ss described above. If no such ss exists for the given nn, output the single word NAV.

Examples2

  1. Example 1

    Input
    3
    
    Expected output
    27
    
  2. Example 2

    Input
    61
    
    Expected output
    70272