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

转载于:https://www.cnblogs.com/VividBinGo/p/11291550.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值