欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Codeforces Global Round 7 A. Bad Ugly Numbers

程序员文章站 2022-07-15 10:45:02
...

A. Bad Ugly Numbers

题目链接-A. Bad Ugly Numbers
Codeforces Global Round 7 A. Bad Ugly Numbers
Codeforces Global Round 7 A. Bad Ugly Numbers
题目大意
输出一个位数为n的数s,且该数每一位数字都不能被s整除

解题思路
贪心

  • 如果n为1,那么无论s是哪个数字都必定能整除自身
  • 如果n不为n,那么577…77和233…33这两种类型的都满足题意

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n==1){
			cout<<"-1"<<endl;
			continue;
		}
		cout<<5;
		for(int i=1;i<n;i++){
			cout<<7;
		}
		cout<<endl;
	}
	return 0;
}

相关标签: codeforces 贪心