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不是,因 ...
随机推荐
- es6中的属性名表达式
代码如下: 问题: 为什么我可以这样给obj1对象添加动态属性? 为什么我最终的结果是只添加了right属性? 解答: 1. 第一个问题解答如下: 我们知道在es5中给对象添加属性有两种方法,一种是通 ...
- 浏览器内核之 HTML 解释器和 DOM 模型
微信公众号:爱写bugger的阿拉斯加如有问题或建议,请后台留言,我会尽力解决你的问题. 前言 此文章是我最近在看的[WebKit 技术内幕]一书的一些理解和做的笔记.而[WebKit 技术内幕]是基 ...
- Vmware安装的linux系统开机黑屏,关闭显示虚拟机忙怎么怎么解决?
在vm虚拟机中,可能会遇到打开一台主机直接黑屏,而且无法关闭,关闭会显示虚拟机繁忙这种情况,如下图: 一般是因为没有正常关机或者操作不当导致的 对此,解决办法一般有两种 第一种方法: 1.重启电脑 ...
- git涨姿势(一)
今天遇到了一个git冲突问题,解决冲突方案我是当然知道的,就是本地不知道何时自己傻不拉几的新建了一个relese分支,而remote是没有release分支的,需要拉取的是release/V1.4.2 ...
- Flink系列之状态及检查点
Flink不同于其他实时计算的框架之处是它可以提供针对不同的状态进行编程和计算.本篇文章的主要思路如下,大家可以选择性阅读. 1. Flink的状态分类及不同点. 2. Flink针对不同的状态进行编 ...
- 在Tomcat上发布Web项目的方式
一. Tomcat的使用: 安装:解压压缩包即可 注意:安装目录不能有中文 目录结构: ①bin:可执行文件 ②conf:可执行文件 ③lib:依赖的jar包 ④logs:日志文件 ⑤:temp:临时 ...
- libra共识算法分析
核心算法说明 基于chained实现,整体上是当前轮推动下一轮共识继续下去, 如此来持续运转下去, 数据有效性证明基于(QC)实现 leader广播proposal消息{round, qc, p ...
- python学习-练习题9*9乘法表巩固
9*9乘法表 分析: 1X1为一行 1X2 2X2 为一行 for i in range(1,10): for j in range(1,i+1): print(str(i) + 'X' + str( ...
- VOIP RTP RTSP 实现 Baresip 源码分析
RTP 使用 udp 进行数据传输,udp 是不能保证,数据包一定可以到达的,也不提供时序.同时还有 MTU 限制. RTCP 用来配合 RTP 提供,传输报告,会话建立和退出. 一大批参考规范 * ...
- 一致性hash算法之php实现
源码地址:https://github.com/killallspree/myFrame/blob/master/framework/components/Flexihash.php