pat 继续(3n+1)猜想

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<cstring>
 5 #include<algorithm>
 6 using namespace std;
 7 bool cmp(int a,int b)
 8 {
 9     return a>b;
10 }
11 int hashTable[10000]={0};
12 int main()
13 {
14     int n;
15     int datas[110];
16     int temp;
17     int c=1;
18     cin>>n;
19     for(int i=0;i<n;i++)
20     {
21         cin>>datas[i];
22         temp=datas[i];
23         while(temp!=1)
24         {
25             if(temp%2==0) temp=temp/2;
26             else temp=(temp*3+1)/2;
27             hashTable[temp]=1;
28         }
29     }
30     sort(datas,datas+n,cmp);
31     for(int i=0;i<n;i++)
32     {
33         if(hashTable[datas[i]]==0)
34         {
35             if(c==1)
36             {
37                 cout<<datas[i];
38                 c=0;
39             }
40             else cout<<" "<<datas[i];
41         }
42     }
43     return 0;
44 }

猜你喜欢

转载自www.cnblogs.com/za-chen/p/12241165.html