2017 ACM-ICPC 亚洲区(西安赛区)网络赛C. Sum【脑洞题】

本文介绍了解决特定数学问题的方法,该问题是找到一个正整数k,使得S(k*x)%233=0成立。文中提供了两种解决策略,一种是直接输出233个9,另一种则是根据x的位数不同,输出不同的重复序列。

限制: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 }

 

转载于:https://www.cnblogs.com/zxhyxiao/p/7534665.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值