zoukankan      html  css  js  c++  java
  • 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("
    ");
      }
      system("pause");
      return 0;
    }
    本博客仅为本人学习,总结,归纳,交流所用,若文章中存在错误或有不当之处,十分抱歉,劳烦指出,不胜感激!!!
  • 相关阅读:
    快速幂(Fast Pow)
    半小时写完替罪羊重构点分树做动态动态点分治之紫荆花之恋的wyy贴心指导
    POJ2942 UVA1364 Knights of the Round Table 圆桌骑士
    二分图判定
    Tarjan求点双连通分量
    POJ1523 SPF 单点故障
    OI比赛常数优化
    Tarjan求割点
    NOIP2015 D1T1 神奇的幻方
    NOIP2016 D2T2 蚯蚓
  • 原文地址:https://www.cnblogs.com/VividBinGo/p/11291550.html
Copyright © 2011-2022 走看看