【Codeforces Round 324 (Div 2)A】【水题】Olesya and Rodion 构造数长度为n且是t的倍数
2015-11-09 20:24
375 查看
A. Olesya and Rodion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Olesya loves numbers consisting of n digits,
and Rodion only likes numbers that are divisible by t. Find some number that satisfies both
of them.
Your task is: given the n and t print
an integer strictly larger than zero consisting of n digits that is divisible
by t. If such number doesn't exist, print - 1.
Input
The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10)
— the length of the number and the number it should be divisible by.
Output
Print one such positive number without leading zeroes, — the answer to the problem, or - 1,
if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Sample test(s)
input
output
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Olesya loves numbers consisting of n digits,
and Rodion only likes numbers that are divisible by t. Find some number that satisfies both
of them.
Your task is: given the n and t print
an integer strictly larger than zero consisting of n digits that is divisible
by t. If such number doesn't exist, print - 1.
Input
The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10)
— the length of the number and the number it should be divisible by.
Output
Print one such positive number without leading zeroes, — the answer to the problem, or - 1,
if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Sample test(s)
input
3 2
output
712
#include<stdio.h> #include<string.h> #include<ctype.h> #include<math.h> #include<iostream> #include<string> #include<set> #include<map> #include<vector> #include<queue> #include<bitset> #include<algorithm> #include<time.h> using namespace std; void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);} #define MS(x,y) memset(x,y,sizeof(x)) #define MC(x,y) memcpy(x,y,sizeof(x)) #define MP(x,y) make_pair(x,y) #define ls o<<1 #define rs o<<1|1 typedef long long LL; typedef unsigned long long UL; typedef unsigned int UI; template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;} template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;} const int N=0,M=0,Z=1e9+7,ms63=1061109567; int casenum,casei; int main() { int n,t; while(~scanf("%d%d",&n,&t)) { if(t<10) { printf("%d",t); for(int i=2;i<=n;i++)printf("0"); puts(""); } else { if(n==1)puts("-1"); else { printf("%d",t); for(int i=3;i<=n;i++)printf("0"); puts(""); } } } return 0; } /* 【题意】 让你构造一个数。 长度为n(1<=n<=100),且这个数是t(2<=t<=10)的倍数。 【类型】 水题 【分析】 因为t只有两种情况—— 1,t<10,即t为个位数。这个时候我们直接在后面添0即可。 2,t=10,这个时候当n=1时非法,否则还是在后面添0即可。 */
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points