uva 11728 Alternate Task

解题思路:将 1~1000 的因子和打表(类似素数筛法)

 1 ///////////////////////////////////////////////////////////////////////////
 2 //problem_id: uva 11728
 3 //user_id: SCNU20102200088
 4 ///////////////////////////////////////////////////////////////////////////
 5 
 6 #include <algorithm>
 7 #include <iostream>
 8 #include <iterator>
 9 #include <iomanip>
10 #include <cstring>
11 #include <cstdlib>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15 #include <cctype>
16 #include <cmath>
17 #include <queue>
18 #include <stack>
19 #include <list>
20 #include <set>
21 #include <map>
22 using namespace std;
23 
24 ///////////////////////////////////////////////////////////////////////////
25 #pragma comment(linker,"/STACK:1024000000,1024000000")
26 
27 #define lson l,m,rt<<1
28 #define rson m+1,r,rt<<1|1
29 ///////////////////////////////////////////////////////////////////////////
30 
31 ///////////////////////////////////////////////////////////////////////////
32 const double EPS=1e-9;
33 const double PI=acos(-1.0);
34 const double E=2.7182818284590452353602874713526;
35 
36 const int x4[]={-1,0,1,0};
37 const int y4[]={0,1,0,-1};
38 const int x8[]={-1,-1,0,1,1,1,0,-1};
39 const int y8[]={0,1,1,1,0,-1,-1,-1};
40 ///////////////////////////////////////////////////////////////////////////
41 
42 ///////////////////////////////////////////////////////////////////////////
43 typedef long long LL;
44 
45 typedef int T;
46 T max(T a,T b){ return a>b? a:b; }
47 T min(T a,T b){ return a<b? a:b; }
48 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
49 T lcm(T a,T b){ return a/gcd(a,b)*b; }
50 ///////////////////////////////////////////////////////////////////////////
51 
52 ///////////////////////////////////////////////////////////////////////////
53 //Add Code:
54 ///////////////////////////////////////////////////////////////////////////
55 
56 int main(){
57     ///////////////////////////////////////////////////////////////////////
58     //Add Code:
59     int Case=1,S,i,j,a[1005];
60     memset(a,0,sizeof(a));
61     for(i=1;i<=1000;i++){
62         for(j=i;j<=1000;j+=i) a[j]+=i;
63     }
64     while(scanf("%d",&S)!=EOF){
65         if(S==0) break;
66         int ans=-1;
67         for(i=S;i>=1;i--){
68             if(a[i]==S){
69                 ans=i;
70                 break;
71             }
72         }
73         printf("Case %d: %d\n",Case++,ans);
74     }
75     ///////////////////////////////////////////////////////////////////////
76     return 0;
77 }
78 
79 ///////////////////////////////////////////////////////////////////////////
80 /*
81 Testcase:
82 Input:
83 1
84 102
85 1000
86 0
87 Output:
88 Case 1: 1
89 Case 2: 101
90 Case 3: -1
91 */
92 ///////////////////////////////////////////////////////////////////////////

posted on 2013-09-16 23:02  SCNU20102200088  阅读(264)  评论(0编辑  收藏  举报

导航