[BZOJ2296] [POJ Challenge] Random seed

Source: Internet
Author: User
Tags random seed

Description

1tthinking In addition to the random algorithm, nothing else. But he can still ac a lot of questions, what does he use? He would choose a good random seed and then output the answer. Often he chooses a good seed that can have a probability of 99% ac problems.

He will choose a seed according to the following rules. First 1tthinking has its own favorite lucky number x. And then he'll find a number a so that (1)A is a is a multiple of x (2) a with a decimal representation that contains 0 to 9.

For example, if x = 1, then 9182736450 is a random seed that 1tthinking needs.

However, 1tthinking sometimes took a long time to find this number, he felt very disappointed. Now he has left the problem to you.

Input

Line 1th, an integer t (0≤ t ≤100), the number of lucky numbers.

2nd to T + 1 line: XI (0≤ XI ≤106), 1tthinking lucky number.

Output

1th to T: An integer yi (0≤ yi ≤1016) that satisfies the condition of the random seed. If not present, output-1.

Sample Input3
1
2
10
Sample Output9876543210
9876543210
9876543210
HINTSource

Acknowledgement dnc1994 provides SPJ program

Solution

Set $ A = 1234567890000000 + x$, then (a-a% x) must be a multiple of x. (Well, there seems to be a little detail ...)

1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5     Long LongT, X, A;6CIN >>T;7      while(t--)8     {9CIN >>x;TenA = 1234567890000000LL +x; Onecout << (x a-a% x:-1) <<Endl; A     } -     return 0; -}
View Code

[BZOJ2296] [POJ Challenge] Random seed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.