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

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

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 10^4 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 1001T100

* 1≤n≤1001 \le n \le 1001n100

输出描述:

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

题意:已知数字N(<=100),寻找一个数字,使这个数字和这个数字各位上的数字之和都能被N整除。如果存在,则任意输出一个答案,反之,输出"Impossible"。

题解:
简单数学若N=12,则12,1212,121212,12121212,……都能被12整除,与此同时还要满足各位数字之和也要被N整除,令N的各位数字之和为m,则(x*m)÷N为整数,得x=N即可。即输出N个数字N。

代码:
#include<iostream>
using namespace std;
int main()
{
  int n,i,T;
  scanf("%d",&T);
  while(T--)
  {
    scanf("%d",&n);
    for(i=1;i<=n;i++) printf("%d",n);
    printf("\n");
  }
  system("pause");
  return 0;
}
 

猜你喜欢

转载自www.cnblogs.com/VividBinGo/p/11291550.html