• 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 }
  • 相关阅读:
    在插入一条记录后 取得自动增长ID
    hashtable,dictionary 从原理上说说有什么异同,哪个性能高一些
    单例模式
    聚簇索引与非聚簇索引的区别
    基于SQL SERVER2008的SCCM2007部署
    XML架构下的表结构设置主键
    IE6与IE7下一点样式的区别
    Session丢失原因与解决方案小结
    Python_如何去除字符串里的空格
    Python_让人脑阔疼的编码问题(转)+(整理)
  • 原文地址:https://www.cnblogs.com/zxhyxiao/p/7534665.html
Copyright © 2020-2023  润新知