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不是,因 ...
随机推荐
- 【Eclipse】eclipse设置,为了更简单快捷的开发
保存时自动导包 Windows->Perferences->Java->Editor->Save Actions
- 2、【Spark】Spark环境搭建(集群方式)
Spark集群方式搭建结构如图所示,按照主从方式.
- Java2变量和运算符
课后作业:[必做题] 1√AB互换 已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序.(知识点:变量和运算符综合应用) [必做题] package com.two; public clas ...
- 车道线检测LaneNet
LaneNet LanNet Segmentation branch 完成语义分割,即判断出像素属于车道or背景 Embedding branch 完成像素的向量表示,用于后续聚类,以完成实例分割 H ...
- 前端每日实战:125# 视频演示如何用纯 CSS 创作一个失落的人独自行走的动画
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/MqpOdR/ 可交互视频 此视频是 ...
- 【新功能】MaxCompoute禁止Full Scan功能开放
摘要: 2018年1月10日,MaxCompute禁止Full Scan功能开放.对于新创建的project默认情况下执行sql时,针对该project里的分区表不允许全表扫描,必须有分区条件指定需要 ...
- js判断PC端还是移动端的代码小坑
我在写官网的时候做了pc和移动端两个,在通过网上查找了这样的代码,看着完全没问题,等放进去页面中后,PC端页面一直刷新,根本停不下来,找了类似js还是同样的问题.通过不断尝试后才发现,问题就是多了一行 ...
- mysql的锁与事务
1. MySQL中的事物 1.InnoDB事务原理 1. 事务(Transaction)是数据库区别于文件系统的重要特性之一,事务会把数据库从一种一致性状态转换为另一种一致性状态. 2. 在数据库提交 ...
- NSInteger打印以及字符串的转换
You can also use %zd (NSInteger) and %tu (NSUInteger) when logging to the console. NSInteger integer ...
- 3DGIS+BIM集成与智慧城市应用
ZTMap3D是基于网络的三维地理信息系统平台软件,利用 ZTMap3D能够实现三维地理信息和虚拟现实,是数字化地球和数字化城市建设的基础平台. BIM(building information mo ...