codeforces 1236 A. Bad Ugly Numbers思维题!!!

A. Bad Ugly Numbers

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a integer nn (n>0n>0). Find any integer ss which satisfies these conditions, or report that there are no such numbers:

In the decimal representation of ss:

  • s>0s>0,
  • ss consists of nn digits,
  • no digit in ss equals 00,
  • ss is not divisible by any of it's digits.
Input

The input consists of multiple test cases. The first line of the input contains a single integer tt (1t4001≤t≤400), the number of test cases. The next tt lines each describe a test case.

Each test case contains one positive integer nn (1n1051≤n≤105).

It is guaranteed that the sum of nn for all test cases does not exceed 105105.

Output

For each test case, print an integer ss which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for ss, print any solution.

Example
input
Copy
4
1
2
3
4
outputCopy
-1
57
239
6789
Note

In the first test case, there are no possible solutions for ss consisting of one digit, because any such solution is divisible by itself.

For the second test case, the possible solutions are: 2323, 2727, 2929, 3434, 3737, 3838, 4343, 4646, 4747, 4949, 5353, 5454, 5656, 5757, 5858, 5959, 6767, 6868, 6969, 7373, 7474, 7676, 7878, 7979, 8383, 8686, 8787, 8989, 9494, 9797, a

 

For the third test case, one possible solution is 239239 because 239239 is not divisible by 22, 33 or 99 and has three digits (none of which equals zero).

 

  这一题翻译过来就是,输入一个数字n,然后输出一个n位数且这个n位数不能被它任何数位上的一个数整除,如果不能就输出-1;

  【我们知道当n为1的时候一定不可能但当n为其他值的时候[  按理来说] 都有可能】所以前(n-1)输出7,第n个输出4,就好了;

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        if(n==1)cout<<"-1"<<'
';//由题意可以知道当位数为1的时候不管怎样都不可能成立
        else{
            for(int i=0;i<n-1;i++){
                cout<<"7";
            }
            cout<<"4"<<'
';
        }
    }

    return 0;
}

当然,还可以输出n-1个2,加一个3(如果能被3整除就输入n-2个2和2个3)

hhhhh大佬告诉我的【云膜拜一下大佬】

大佬说,正常人不会想到4和7的==(嘤嘤嘤),正常人想到的是2和3hhhhhhh;

就像这样↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int t;
 8     cin>>t;
 9     while(t--){
10         int n;
11         cin>>n;
12         if(n==1)cout<<"-1"<<'
';//由题意可以知道当位数为1的时候不管怎样都不可能成立
13         else if(((n-1)*2+3)%3!=0 ){
14             for(int i=0;i<n-1;i++){
15                 cout<<"2";
16             }
17             cout<<"3"<<'
';
18             }
19         else { for(int i=0;i<n-2;i++){
20                 cout<<"2";
21             }
22             cout<<"33"<<'
';
23             }
24         }
25     return 0;
26 }

第一次发博客点个赞鼓励一下呗【嘻嘻嘻嘻嘻嘻嘻】

 

原文地址:https://www.cnblogs.com/ahijing/p/12530729.html