codeforces 584A Olesya and Rodion
A. Olesya and Rodion
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
1 #include<cstdio> 2 #include<vector> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 typedef long long ll; 7 int a[11][105]; 8 int main() 9 { 10 int n,t; 11 for(int i=2;i<=10;i++) 12 { 13 a[i][1]=1; 14 for(int j=2;j<=100;j++) 15 a[i][j]=(a[i][j-1]*10+1)%i; 16 } 17 scanf("%d%d",&n,&t); 18 int x=a[t][n-1]*10; 19 x%=t; 20 for(int i=0;i<n-1;i++)printf("1"); 21 printf("%d\n",t-x); 22 return 0; 23 }