zoukankan      html  css  js  c++  java
  • 2017 ACM-ICPC 亚洲区(西安赛区)网络赛C. Sum【脑洞题】

    限制:1000ms 32768K
    Define the function S(x) for xx is a positive integer. S(x) equals to the sum of all digit of the decimal expression of x. Please find a positive integer k that S(k∗x)%233=0.

    Input Format

    First line an integer T, indicates the number of test cases (T≤100). Then Each line has a single integer x(1≤x≤1000000) indicates i-th test case.

    Output Format

    For each test case, print an integer in a single line indicates the answer. The length of the answer should not exceed 2000. If there are more than one answer, output anyone is ok.

    样例输入
    1
    1
    样例输出

    89999999999999999999999999

    看来脑洞不够大。。。。

    方法一:直接输出233个9。因为任何正整数乘以9的数位和都是9的倍数。。。

    #include <iostream>
    using namespace std;
    
    int main()
    {
        int T,n;
        cin>>T;
        while(T--){
            cin>>n;
            for(int i=1;i<=233;i++){
                cout<<9;
            }
            cout<<endl;
        }
        return 0;
    }

    方法二:

    当x<10时可以直接输出233个x,当1000>x>=10时,不妨设k*x=233个x,那么k=10(233个10),当1000<=x<10000,k=100(233个100),等等。手动模拟一下就懂了。

     1 #include <iostream>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int T,n;
     7     cin>>T;
     8     while(T--){
     9         cin>>n;
    10         int tmp=n;
    11         int len=0;
    12         while(n){
    13             len++;
    14             n/=10;
    15         }
    16 
    17         if(len==1){
    18             for(int i=0;i<233;i++)
    19                 cout<<tmp;
    20         }else if(len==2){
    21             for(int i=0;i<233;i++)
    22                 cout<<"10";
    23         }else if(len==3){
    24             for(int i=0;i<233;i++)
    25                 cout<<"100";
    26         }else if(len==4){
    27             for(int i=0;i<233;i++)
    28                 cout<<"1000";
    29         }else if(len==5){
    30             for(int i=0;i<233;i++)
    31                 cout<<"10000";
    32         }else{
    33             for(int i=0;i<233;i++)
    34                 cout<<"100000";
    35         }
    36         cout<<endl;
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    Android开发加快sdk更新速度
    Java 解决约瑟夫问题
    单例模式之我见
    用Java来写常见的排序算法
    一位大牛写的单例
    watchdog监控文件变化使用总结——转载
    python-tkinter使用方法——转载(二)
    python-tkinter使用方法——转载(一)
    python中字符串操作
    python中os模块操作目录与文件名小结
  • 原文地址:https://www.cnblogs.com/zxhyxiao/p/7534665.html
Copyright © 2011-2022 走看看