Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := []int{0, 1, 2, 3, 5, 7, 8, 9}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		out := make([]int, 10)
		now := 0
		for n > 0 {
			out[now] = table[n%8]
			now++
			n /= 8
		}
		tmp := make([]string, 0)
		for i := now - 1; i >= 0; i-- {
			tmp = append(tmp, strconv.Itoa(out[i]))
		}
		fmt.Println(strings.Join(tmp, ""))
	}
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	ll N;
	int p[] = {0, 1, 2, 3, 5, 7, 8, 9 };

	while(cin >> N, N) {
		vi num;
		
		while(N > 0) {
			num.push_back(p[N%8]);
			N /= 8;
		}

		int size = num.size();
		REP(i, size) {
			cout << num[size-1-i];	
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int conv[] = {0, 1, 2, 3, 5, 7, 8, 9};
int main () {
	ll n;
	while (cin >> n, n) {
		vector<int> oct;
		while (n >= 8) {
			oct.push_back(n % 8);
			n /= 8;
		}
		oct.push_back(n);
		for (vector<int>::reverse_iterator it = oct.rbegin(); it != oct.rend(); ++it) {
			cout << conv[*it];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int room;
    char hospital[11];
	
    while(cin >> room, room)
    {
        sprintf(hospital, "%o", room);
    	
    	for(int i = 0; i < 11; i++)
    	{
    		if(hospital[i] == '4')
    		{
    			hospital[i] = '5';
    		}
    		else if(hospital[i] > '4')
    		{
    			hospital[i] += 2;
    		}
    	}
    	cout << hospital << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

long long a[21]={0, 298790200, 797380500, 1095170800, 1392951000, 1891731200, 2190321500, 2589111800, 2987902000, 3285592200, 3783282500, 5082072800, 5380853000, 5879533200, 7178223500, 7577013800, 7973805000, 8272395200, 8771185500, 9059975800, 9358757000};
char b[100000]={};

long long int number(int n){
  long long int h=0;
  int p=0;

  p=(n/50000000)*50000000;
  h=a[p/50000000];

  while(p<n){
    h++;
    if(b[h%100000]==1 && b[h/100000]==1)
      p++;
    }

  return h;
}


int main() {
    ios::sync_with_stdio(false);
    int s;
    int m=0;
    while(m<=99999){
      int t=m;
      while(t>0){
	if(t%10==4 || t%10==6)
	  {b[m]--;break;}
	else{
	  t=t/10;      
	}
      }
      b[m]++;
      m++;
    }
    
    int p,q;
    
    while (1) {
      cin >> s;
      if(s != 0){
	cout << number(s) << endl;
      }
      else
	break;
    }

    return 0;
}

C++: #include <cstdio>
#include <string>
using namespace std;
int main(){
  int n;
  char str[100];
  while(scanf("%d", &n) && n){
    sprintf(str, "%o", n);
    for(int i = 0; str[i] != '\0'; ++i){
      if(str[i] >= '4') str[i]++;
      if(str[i] >= '6') str[i]++;
    }
    printf("%s\n", str);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;

int main()
 {
    int n;
    while(cin>>n,n)
    {
        int d[99]={0},c=0;
        while(n>0)
         {
            d[c++]=n%8;
            n/=8;
        }
        while(c--)
        cout<<"01235789"[d[c]]<<endl;
 
    }
    return 0;
}

C++: /*#include <iostream>

unsigned long long int func(unsigned long long int a);

unsigned long long answ[1000000000];

int main(){
	unsigned long long int n;
	while(std::cin >> n, n){
		unsigned long long int ans = 0;
		unsigned long long int n_=n;
		while(n_--){
			ans++;
			unsigned long long int b = func(ans); 
			ans+=b;
			n-=b;
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

unsigned long long int func(unsigned long long int a){
	int res=1;
	while(a > 0){
		if(a % 10 == 4 || a % 10 == 6)return res;
		a /= 10;
		res*=10;
	}
	return 0;
}*/

#include <iostream>
#include <stack>
#define  _m_ 1

const int Ebit[8]={0,1,2,3,5,6,8,9};

int main(){
	int n;
	std::stack<int> st;
	while(_m_){
		std::cin >> n;
		if(n==0)break;
		while(_m_){
			if(n<8){
				st.push(Ebit[n]);
				break;
			}
		}
		int amari = n%8;
		n/=8;
		st.push(Ebit[amari]);
	}
	while(st.size()){
		std::cout<<st.top();
		st.pop();
	}
	std::cout<<std::endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	int n,i;
	int count;
	while(1){
		cin >> n;
		count = 0;
		if(n==0){
			break;
		}
		i = 0;
		count = 1;
		while(1){
			if(to_string(count).find("4",0) == -1 && to_string(count).find("6",0) == -1){
				i++;
			}
			if(i==n){
				cout << count << endl;
				break;
			}

			count++;
		}

	}
}

C++: #include<iostream>


using namespace std;

int f(int x){
	if(x>3){
		x++;
	}
	if(x>5){
		x++;
	}
	return x;
}

int main(){
	
	int n;
	int ans[20];
	int count;
	while(cin>>n,n){
		
		count=0;
		for(int i=0;n>0;i++){
			ans[i]=(n%8);
			n=n/8;
			count++;
		}
		
		
		while(count--){
			cout<<f(ans[count]);
		}cout<<endl;
	}
	
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

#define rep(i,a) for(int i=0;i<(a);++i)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

const int MAX = 1000000000;
int n;
string table[] = {"0", "1", "2", "3", "5", "7", "8", "9"};

string rec(int c)
{
    int a, b;
    a = c / 8; b =c % 8;

    if(a  == 0) 
        return table[b];
    else 
        return rec(a) + table[b];
}

int main()
{
    while(cin >> n && n) 
        cout << rec(n) << endl;
}

C++: #include <iostream>
#include <string>

using namespace std;

char b[10000000]={};

long long int number(int n){
  long long int h=0;
  int p=0;
  
  while(p<n){
    h++;
    
    if(h<10000000){
      if(b[h]==1)
	p++;
    }
    else{
      if(b[h%10000000]==1 && b[h/10000000]==1)
	p++;
    }
  }
  return h;
}
  


int main() {
    ios::sync_with_stdio(false);
    int s;
    int m=0;
    while(m<=9999999){
      int t=m;
      while(t>0){
	if(t%10==4 || t%10==6)
	  {b[m]--;break;}
	else{
	  t=t/10;      
	}
      }
      b[m]++;
      m++;
    }
    
    int p,q;
    
    while (1) {
      cin >> s;
      if(s != 0){
	cout << number(s) << endl;
      }
      else
	break;
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

long long int n;
int num[8]={0,1,2,3,5,7,8,9};

int main(void){
	while(1){
		scanf("%lld",&n);
		if(n==0)break;
		string str;
		while(n>0){
			int s=num[n%8];
			str+=s+'0';
			n=n/8;
		}
		reverse(str.begin(),str.end());
		cout << str << endl;
	}
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    string conv = "01235789";
    int N;
    while(cin >> N, N) {
        string ret = "";
        for(; N>0; N/=8) {
            ret += conv[N%8];
        }
        reverse(ret.begin(), ret.end());
        cout << ret << endl;
    }
}