codeforces 1236 A. Bad Ugly Numbers
A. Bad Ugly Numbers
1 second
256 megabytes
standard input
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.
The input consists of multiple test cases. The first line of the input contains a single integer tt (1≤t≤4001≤t≤400), the number of test cases. The next tt lines each describe a test case.
Each test case contains one positive integer nn (1≤n≤1051≤n≤105).
It is guaranteed that the sum of nn for all test cases does not exceed 105105.
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.
4
1
2
3
4
-1
57
239
6789
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==)cout<<"-1"<<'\n';//由题意可以知道当位数为1的时候不管怎样都不可能成立
else{
for(int i=;i<n-;i++){
cout<<"";
}
cout<<""<<'\n';
}
} return ;
}
当然,还可以输出n-1个2,加一个3(如果能被3整除就输入n-2个2和2个3)
hhhhh大佬告诉我的【云膜拜一下大佬】
大佬说,正常人不会想到4和7的==(嘤嘤嘤),正常人想到的是2和3hhhhhhh;
就像这样↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#include <bits/stdc++.h> using namespace std; int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n==)cout<<"-1"<<'\n';//由题意可以知道当位数为1的时候不管怎样都不可能成立
else if(((n-)*+)%!= ){
for(int i=;i<n-;i++){
cout<<"";
}
cout<<""<<'\n';
}
else { for(int i=;i<n-;i++){
cout<<"";
}
cout<<""<<'\n';
}
}
return ;
}
第一次发博客点个赞鼓励一下呗【嘻嘻嘻嘻嘻嘻嘻】
codeforces 1236 A. Bad Ugly Numbers的更多相关文章
- [POJ1338]Ugly Numbers
[POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- Ugly Numbers
Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21918 Accepted: 9788 Descrip ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- leetcode@ [263/264] Ugly Numbers & Ugly Number II
https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...
- Geeks Interview Question: Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- 136 - Ugly Numbers
Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...
- Ugly Numbers(STL应用)
题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- 丑数(Ugly Numbers, UVa 136)
丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...
随机推荐
- js作用域其二:预解析
文章目錄 解析机制 JavaScript是一门解释型的语言 , 想要运行js代码需要两个阶段 编译阶段: 编译阶段就是我们常说的JavaScript预解析(预处理)阶段,在这个阶段JavaScript ...
- ansible使用指北(二)
前言在上一篇文章里我们了解了ansible的常用模块,今天我们来了解下ansible-playbook,ansbile-playbook是一系统ansible命令的集合,其利用yaml 语言编写,an ...
- 8.【Spring Cloud Alibaba】配置管理-Nacos
使用Nacos管理配置 架构图 配置文件遵循的格式 bootstrap.yml pom.xml <dependency> <groupId>org.springframewor ...
- Node REPL环境
1.概述 REPL全称Read,Eval,Print,Loop,简单理解为接收用户输入,执行用户输入,打印执行结果并输出到控制台,进行下一次轮回,可以进行一些简单的测试,类似于浏览器的控制台. 命令行 ...
- org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sql.SQLException: Incorrect string value: '\xE2\x80\x8B\xE2\x80\x8B...' for column 'pro_backgroud' at row
如果你在mysql数据库中,将所有的表的编码格式设置成为utf-8之后还是不行,那就试试这个吧:ALTER TABLE your_database_name.your_table CONVERT TO ...
- 配置VSCode的C/C++语言功能
0. 前言 主要是在网上找的方法都没试成功过,在各种机缘巧合下终于成功了. 这篇文章基于个人经验,而且没有走寻常路. 1. 需要的软件和插件 软件: VSCode (https://code.visu ...
- Spring常见注解
@Autowired @Resource @Component:类加上@Component注解,即表明此类是bean @Aspect 注解表示这是一个切面 @Around(value = " ...
- HTTP——https、http缓存、get与post、web安全、跨域
HTTP诞生 1989年为知识共享而诞生的Web,提出了3项WWW构建技术: 标准通用标记语言设为HTML(HyperText Markup Language,超文本标记语言) 文档传输协议HTTP( ...
- 研究开源源码之Myrmec
好久没写博客了,自己也弄不清是懒了还是忙了.毕竟白天需要工作,晚上有时候看看资料,有时候陪家人,有时候约朋友......更加累了,可能由于累了就懒得总结了. 今天有同事问我关于代码检查文件类型的问题. ...
- webpack进阶(二)
1)webpack动态打包所有依赖项,避免打包未使用的模块. 2)转换css的loader有:css-loader,style-loader,加载图片或文件的loader是:file-loader,如 ...