using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
typedef long long Int;
typedef unsigned long long UInt;
typedef vector <int> VI;
typedef pair <int, int> PII;
int res = -1;
for (int i = 0; i <= n; ++i)
if (i % 5 == 0)
int j = n - i;
if (j % 3 == 0)
res = i;
if (res == -1)
cout << -1 << endl;
- Problem Description
Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diabolical. Sherlock’s companion, Dr. Watson, suggests Moriarty may be responsible for MI6’s recent issues with their supercomputer, The Beast.
Shortly after resolving to investigate, Sherlock receives a note from Moriarty boasting about infecting The Beast with a virus; however, he also gives him a clue a number, N. Sherlock determines the key to removing the virus is to find the largest Decent Number having N digits.
A Decent Number has the following properties:
1. Its digits can only be 3’s and/or 5’s.
2. The number of 3’s it contains is divisible by 5.
3. The number of 5’s it contains is divisible by 3.
4. If there are more than one such number, we pick the largest one.
1 <= T <= 20
1 <=N <= 100000
The first line is an integer, T , denoting the number of test cases.
The T subsequent lines each contain an integer, N, detailing the number of digits in the number.
Print the largest Decent Number having N digits; if no such number exists, tell Sherlock by printing -1.
Moriarty’s virus shows a clock counting down to The Beast’s destruction, and time is running out fast. Your task is to help Sherlock find the key before The Beast is destroyed!
- Test Case 1
- Test Case 2