您的位置:首页 > 其它

【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
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 ICPC codeforces 水题