hdu3184 All Can Do
题目:
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.
Input
The first line contains an integer t means the number of test cases.
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,m,求一个数Q满足三个条件,一个是能被90整除,还有一个是能被m整除,并且Q要在n-1 <= Log10Q < n, ( 0 < n <= 100 ) 区间内;
思路:因为Q既能被90整除也能被m整除,那么m肯定能被90整除,并且Q要最大所以直接考虑9999(9…)0的情况,如果m是个位数的话特判一下,还有就是要考虑这个数在不在区间内
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
if(90%m!=0)
cout<<"Impossible!\n";
else
{
int cnt=0;
int r=0;
if(m==1)
r=9;
if(m==2)
r=8;
if(m==3)
r=9;
if(m==5)
r=5;
if(m==6)
r=6;
if(m==9)
r=9;//特判个位数的情况
while(m)
{
cnt++;
m=m/10;
}
if(cnt>n)
{
cout<<"Impossible!\n";
} //判断在不在区间内
else
{
for(int i=1;i<n;i++)
{
cout<<"9";
}
cout<<r<<endl;
}
}
}
return 0;
}
本文介绍了一道名为HDU3184的算法题的解决思路及实现代码,该题要求寻找符合条件的最大数值N,使得N既能在特定范围内,又能同时被90和给定整数m整除。
445

被折叠的 条评论
为什么被折叠?



