Code Forces 584 A. Olesya and Rodion(水~)

Description
给出两个整数n和t,要求输出一个被t整除的n位数,如果不存在这样的数则输出-1
Input
两个整数n和t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10)
Output
如果存在一个n位数能被t整数则输出这个数,否则输出-1
Sample Input
3 2
Sample Output
712
Solution
简单题,无解情况只有n=1,t=10时;当t<=9时,只需要输出n个t即可;当t=10时,只需要输出一个1以及n-1个0即可
Code

#include<stdio.h>
int main()
{
    int n,t;
    while(~scanf("%d%d",&n,&t))
    {
        if(n==1&&t==10)
        {
            printf("-1\n");
            continue;
        }
        if(t!=10)
        {
            for(int i=1;i<=n;i++)
                printf("%d",t);
            printf("\n");
        }
        else
        {
            printf("1");
            for(int i=1;i<n;i++)
                printf("0");
            printf("\n");
        }
    }
    return 0;
}

你可能感兴趣的:(Code Forces 584 A. Olesya and Rodion(水~))