1. 程式人生 > >2017 ACM-ICPC 亞洲區(西安賽區)網絡賽C. Sum【腦洞題】

2017 ACM-ICPC 亞洲區(西安賽區)網絡賽C. Sum【腦洞題】

整數 namespace pac line main expr esp for cnblogs

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

2017 ACM-ICPC 亞洲區(西安賽區)網絡賽C. Sum【腦洞題】