天天看點

ZOJ 2965 Accurately Say "CocaCola"!

In a party held by CocaCola company, several students stand in a circle and play a game.

One of them is selected as the first, and should say the number 1. Then they continue to count number from 1 one by one (clockwise). The game is interesting in that, once someone counts a number which is a multiple of 7 (e.g. 7, 14, 28, ...) or contains the digit '7' (e.g. 7, 17, 27, ...), he shall say "CocaCola" instead of the number itself.

For example, 4 students play this game. At some time, the first one says 25, then the second should say 26. The third should say "CocaCola" because 27 contains the digit '7'. The fourth one should say "CocaCola" too, because 28 is a multiple of 7. Then the first one says 29, and the game goes on. When someone makes a mistake, the game ends.

During a game, you may hear a consecutive of p "CocaCola"s. So what is the minimum number that can make this situation happen?

For example p = 2, that means there are a consecutive of 2 "CocaCola"s. This situation happens in 27-28 as stated above. 27 is then the minimum number to make this situation happen.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 100) which is the number of test cases. And it will be followed by T consecutive test cases.

There is only one line for each case. The line contains only one integer p (1 <= p <= 99).

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the minimum possible number for the first of the p "CocaCola"s stands for.

Sample Input

2

2

3

Sample Output

27

70

#include<map>
#include<ctime>
#include<cmath>    
#include<queue> 
#include<string>
#include<vector>
#include<cstdio>    
#include<cstring>  
#include<iostream>
#include<algorithm>    
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))    
#define rep(i,j,k) for(int i=j;i<=k;i++)    
#define per(i,j,k) for(int i=j;i>=k;i--)    
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])    
#define inone(x) scanf("%d",&x)    
#define intwo(x,y) scanf("%d%d",&x,&y)    
#define inthr(x,y,z) scanf("%lf%lf%lf",&x,&y,&z)    
typedef long long LL;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int T, n;
int f[100];
int g[N];

int main()
{
  ms(f, 1);
  rep(i, 1, N - 1)
  {
    g[i] = i % 7 == 0;
    for (int j = i; j; j /= 10) g[i] |= j % 10 == 7;
  }
  per(i, N - 2, 1)
  {
    g[i] = g[i] * (g[i] + g[i + 1]);
    f[min(g[i], 99)] = i;
  }
  per(i, 98, 1) f[i] = min(f[i], f[i + 1]);
  for (inone(T); T--;)
  {
    inone(n); printf("%d\n", f[n]);
  }
  return 0;
}