/*
An N-length wobbly number is of the form "ababababab..." and so on of length N, where a!=b.
Find Kth wobbly number from a lexicographically sorted list of N-length wobbly numbers. If the number does not exist print −1 else print the Kth wobbly number.
Input:
First line contains T - number of test cases
Each of the next T lines contains two space separated integers - N and K
Output:
For each test case print the required output in a new line.
Constraints: 1≤T≤100
3≤N≤1000
1≤K≤100
*/
#include <stdio.h>
int main()
{
int t,i,n,k,a,b,j,temp;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d %d",&n,&k);
if(k>81)
printf("-1\n");
else{
a=ceil((double)k/9.0);
temp=k-9*(a-1);
b=(temp<=a)?temp-1:temp;
for(j=0;j<n;j++)
if(j%2==0) printf("%d",a);
else printf("%d",b);
printf("\n");
}
}
}
An N-length wobbly number is of the form "ababababab..." and so on of length N, where a!=b.
Find Kth wobbly number from a lexicographically sorted list of N-length wobbly numbers. If the number does not exist print −1 else print the Kth wobbly number.
Input:
First line contains T - number of test cases
Each of the next T lines contains two space separated integers - N and K
Output:
For each test case print the required output in a new line.
Constraints: 1≤T≤100
3≤N≤1000
1≤K≤100
*/
#include <stdio.h>
int main()
{
int t,i,n,k,a,b,j,temp;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d %d",&n,&k);
if(k>81)
printf("-1\n");
else{
a=ceil((double)k/9.0);
temp=k-9*(a-1);
b=(temp<=a)?temp-1:temp;
for(j=0;j<n;j++)
if(j%2==0) printf("%d",a);
else printf("%d",b);
printf("\n");
}
}
}
0 comments:
Post a Comment