---
# System prepended metadata

title: 一分鐘分享
tags: [110程式設計一]

---

# 一分鐘分享
###### tags: `110程式設計一`
![](https://i.imgur.com/SR07DX9.png)
取自我cpe犯錯的D能題目

```c=
#include<stdio.h>
#include<math.h>

int list[1001];

void fact()
{
     int i,j;
     for(i=1;i<=1000;i++)
     list[i]=0;
    
     for(i=1;i<=1000;i++)
     {
        for(j=1;j<=i;j++)
        {
        if(i%j==0)
           list[i]+=j;
        }
     }    
}

int main()
{
    fact();
    int k,r,i,j,n,kase=1;
 
    while(scanf("%d",&n)==1)
    {
    if(n<=0)
    break;
   
    printf("Case %d: ",kase);
    r=0;
    for(i=1000;i>=1;i--)
       {
       if(list[i]==n)
           {
           printf("%d\n",i);
           r++;
           break;
           }
       }
      
    if(r==0)
    printf("-1\n");
    kase++;
    }
    return 0;
}
```
![](https://i.imgur.com/QGAF7Hk.png)


```c=
#include<stdio.h>
#include<math.h>

int list[1001];

void fact()
{
     int i,j;
     for(i=1;i<=1000;i++)
     list[i]=0;
    
     for(i=1;i<=1000;i++)
     {
        for(j=1;j<=i;j++)
        {
        if(i%j==0)
           list[i]+=j;
        }
     }    
}

int main()
{
      fact();
    int k,r,i,j,n,kase=1;
 
    while(scanf("%d",&n)==1)
    {
    if(n==0)
    break;
   
    printf("Case %d: ",kase);
    r=0;
    for(i=1000;i>=1;i--)
       {
       if(list[i]==n)
           {
           printf("%d\n",i);
           r++;
           break;
           }
       }
      
    if(r==0)
    printf("-1\n");
    kase++;
    }
    return 0;
}

```
test case 1:
```

1
102
1000
2
4
12
24
9
15
39
36
245
278
952
664
358
234
960
991
996
0
```
```

Case 1: 1
Case 2: 101
Case 3: -1
Case 4: -1
Case 5: 3
Case 6: 11
Case 7: 23
Case 8: -1
Case 9: 8
Case 10: 18
Case 11: 22
Case 12: -1
Case 13: 277
Case 14: 871
Case 15: -1
Case 16: -1
Case 17: 233
Case 18: 899
Case 19: -1
Case 20: 662
```
test case 2:
```

8
5
10
20
31
45
350
24
822
119
618
931
612
802
800
380
230
749
952
649
171
0

```
```

Case 1: 7
Case 2: -1
Case 3: -1
Case 4: 19
Case 5: 25
Case 6: -1
Case 7: 349
Case 8: 23
Case 9: 821
Case 10: -1
Case 11: 617
Case 12: 484
Case 13: 505
Case 14: -1
Case 15: 597
Case 16: 379
Case 17: 229
Case 18: -1
Case 19: 871
Case 20: -1
Case 21: 98
```
