1 #include<iostream> 2 #include<stdio.h> 3 #define MAXN 10000001 4 using namespace std; 5 6 int a[MAXN]; 7 void give_set(); 8 int min(int i,int j); 9 int main() 10 { 11 //freopen("acm.acm","r",stdin); 12 give_set(); 13 int num; 14 while(cin>>num) 15 { 16 cout<<a[num-1]<<endl; 17 } 18 } 19 20 void give_set() 21 { 22 a[0] = 1; 23 int m; 24 int len = 1; 25 int x; 26 int y; 27 x = 0; 28 y = 0; 29 while(len < MAXN) 30 { 31 m = min(2*a[x]+1,3*a[y]+1); 32 if(m == 2*a[x]+1) 33 ++ x; 34 if(m == 3*a[y]+1) 35 ++ y; 36 a[len++] = m; 37 } 38 } 39 int min(int a,int b) 40 { 41 return a < b ? a : b; 42 }