Description
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 Input
Input3 2Output712
思路:这道题最重要的是想到把这个n位数的每一位看做一个独立分散的个体,赋给数组。找出没有结果的那唯一的一种情况。由于任意输出一个数,那么情况就很多了,找最具代表性的。然后,当t==10时,只要最后一位是0即可。t!=10时,最好想且具有普遍规律的两种就是,第一位为t,其余位为0;和每一位都是t。
#include<cstdio>#include<cstring>int a[150]; //将n个数字中的每一位都看作一个单独的个体 int main(){ int n,t; scanf("%d%d",&n,&t); memset(a,0,sizeof(a)); if(n==1&&t==10) printf("-1/n"); else { if(t==10) { a[0]=1; for(int i=0;i<n;i++) printf("%d",a[i]);//t==10那么只需要n位数的第一位为1,其他位为0即可 } else { for(int i=0;i<n;i++) printf("%d",t);//t!=0,只需每一位都是t,反正是输出任意一项;那么令第一位为t,其他位都为0也是可以的 } printf("/n"); } return 0;}
新闻热点
疑难解答