2019牛客暑期多校训练营(第五场) A digits 2

传送门

链接:https://ac.nowcoder.com/acm/contest/885/A
来源:牛客网
 

You are given a positive integer n which is at most 100.

Please find a positive integer satisfying the following conditions:

1. The sum of all digits of this number is dividable by n.

2. This number is also dividable by n.

3. This number contains no more than 10410^4104 digits.
 

If such an integer doesn't exist, output "Impossible" (without quotation marks).

If there are multiple such integers, please output any one.

输入描述:

The first line contains one integer T indicating that there are T tests.

Each test consists an integer n in a single line.

* 1≤T≤1001 \le T \le 1001≤T≤100

* 1≤n≤1001 \le n \le 1001≤n≤100

输出描述:

For each query, output one line containing the answer. The number you print cannot have leading zeros. If there are multiple answers, you can print any. If such an integer doesn't exist, output "Impossible" (without quotation marks) in a single line.

示例1

输入

3
1
9
12

输出

1
666666
888

说明

For the last test, 888 is dividable by 12 (888 = 12 * 74) and 8 + 8 + 8 = 24 is also dividable by 12 (24 = 12 * 2).

这题就很坑,给的测试样例我还真要看看题解是怎么求的

这题开始想的是用各个进制上求%打表做,直到明白位数是1e4(大),就很难受。

他给你n,假设是19好吧,那我求出来的是最少几个19连在一起满足条件(各个位置和被19,这个值因为是k个19连在一起,所以定能被19整除)就完事了(这里19是用各个位数和判断,把和扩大倍数,不成立是判断位数满足小于1e4,否则就无解),Giao

#include<bits/stdc++.h>
using namespace std;
const int inf = 10000;
int getsum(int x){
    int sum=0;
    while(x){
        sum+=(x%10);
        x/=10;
    }
    return sum;
}
int getbit(int x){
    int bit=0;
    while(x){
        bit++;
        x/=10;
    }
    return bit;
}
int main(){
    int t;cin>>t;
    while(t--){
        int n;scanf("%d",&n);
        int m = getsum(n);
        int k=0;
        for(int i=2;i<inf;i++){
            if(i*m%n==0){
                k=i;
                break;
            }
        }
        if(k==0|| k*getbit(n)>inf){
            printf("Impossible\n");
            continue;
        }
        for(int i=0;i<k;i++){
            cout<<n;
        }
        cout<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值