Problem Description
Construct a number N follows three below restrictions:
1. T-1 <= Log10N < T, ( 0 < T <= 100 )
2. 90 mod b = 0
3. N mod b = 0
Please help me find the biggest N.
1. T-1 <= Log10N < T, ( 0 < T <= 100 )
2. 90 mod b = 0
3. N mod b = 0
Please help me find the biggest N.
Input
The first line contains an integer t means the number of test cases.
Then each line will contain two integers T and b.
Then each line will contain two integers T and b.
Output
For each case, output N in one line, if there is no such answer, output "Impossible!".
Sample Input
3 2 45 1 10 2 5
Sample Output
90 Impossible! 95
由于n的范围会很大,所以必须用比较巧妙一点的方法
#include <stdio.h>
int main()
{
int cas,i;
int n,t,b;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&t,&b);
if(90%b)//b必须能被90整除
{
printf("Impossible!\n");
continue;
}
//以下是按结果的最后数字不同进行分类
if(b == 1 || b == 3 || b == 9)
{
for(i = 0;i<t;i++)
printf("9");
}
else if(b == 2)
{
for(i = 0;i<t-1;i++)
printf("9");
printf("8");
}
else if(b == 5)
{
for(i = 0;i<t-1;i++)
printf("9");
printf("5");
}
else if(b == 6)
{
for(i = 0;i<t-1;i++)
printf("9");
printf("6");
}
else
{
if(t<2)
{
printf("Impossible!\n");
continue;
}
for(i = 0;i<t-1;i++)
printf("9");
printf("0");
}
printf("\n");
}
return 0;
}