Codeforces 584A Olesya and Rodion 【构造】

来源:互联网 发布:淘宝工业产品许可证号 编辑:程序博客网 时间:2024/06/03 14:32

题目链接:Codeforces 584A Olesya and Rodion

A. Olesya and Rodion
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Examples
input
3 2
output
712

题意:让你构造一个n位的正整数使得它可以被t整除,不存在输出-1。

思路:特判,先填好前面,然后后面全填0。

AC代码:

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <queue>#include <cmath>#define fi first#define se second#define ll o<<1#define rr o<<1|1#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MOD = 1e4 + 7;const int MAXN = 1e5 + 10;void add(LL &x, LL y) { x += y; x %= MOD; }int main(){    int n, t;    while(scanf("%d%d", &n, &t) != EOF) {        if(n == 1 && t == 10) {            printf("-1\n");            continue;        }        if(t == 10) {            t = 1;        }        printf("%d", t);        for(int i = 1; i < n; i++) {            printf("0");        }        printf("\n");    }    return 0;}
0 0
原创粉丝点击