hdu3184 All Can Do

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;
}

代码提交地址:http://acm.hdu.edu.cn/showproblem.php?pid=3184

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值