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

本文解析了Digitis竞赛题目,探讨如何找到一个特定整数,该数既能被n整除,其数字之和也能被n整除。通过输出n重复的数字序列,巧妙解决了这一数学挑战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Digitis

链接:https://ac.nowcoder.com/acm/contest/885/A

Problem description

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 104 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≤100

  • 1≤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).

题意

对于给出的数字 n ,输出一个数,这个数既能整除 n ,它的各位数字加和也能够整除 n

分析

  1. 要输出一个数,能够整除 n , 则输出这个数 n 次,它本身的每一次输出就是 n 的倍数
  2. 输出一个数 n 次,那么其加和一定是 n * x ( x是原数加和的结果 ),所以一定可以被整除

代码

#include<bits/stdc++>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        for(int i=0;i<n;i++) cout<<n;
        cout<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值