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<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>


#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

#define PII pair<int,int>
#define PP pair< int,PII >


using namespace std;

int main(){
	
	int n;
	char x[128];
	char deco[] ={"5789"};
	int l;
	while(scanf("%d", &n),n){
		sprintf(x, "%o", n);
		l = strlen(x);
		rep(i,l){
			rep(j,4){
				if(x[i] == '4'+j){
					x[i] = deco[j];
					break;
				}
			}
		}
		puts(x);
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
#define _w_ true
using namespace std;

const int Ebit[8] = {0,1,2,3,5,7,8,9};
int main(){
  int n;
  stack<int> st;
  while(_w_){
    cin >> n;
    if(n == 0)break;
    while(_w_){
      if(n<8){
	st.push(Ebit[n]);
	break;
      }
      int amari = n%8;
      n = n/8;
      st.push(Ebit[amari]);
    }
    while(st.size()){
      cout << st.top();
      st.pop();
    }
    cout << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int nums[]={0,1,2,3,5,7,8,9};
	while(1){
		int n;
		long long a=0,d=1;
		scanf("%d",&n);
		if(!n) break;
		while(n){
			a+=nums[n%8]*d;
			d*=10;
			n/=8;
		}
		printf("%lld\n",a);
	}
	return 0;
}

C++: //#include <iostream>
//#include <string>
#include <stdio.h>

//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;
}
*/

char str[15];

char* number(int n){
  sprintf(str, "%o", n);
  int i;
  for(i=0;i<15;i++){
    if(str[i]>='4')
      {str[i]++;}
    if(str[i]>='6')
      str[i]++;
  }
  
  return str;
}



int main(){
  int s;
  while (1) {
    scanf("%d", &s);
    if(s != 0){
      //cout << number(s) << endl;
      printf("%s\n", number(s));
    }
    else
      break;
  }
  
  return 0;
}

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

using namespace std;

typedef unsigned long long ULL;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        /*
        vector<ULL> dp(11, 0);
        dp[0] = 0;
        dp[1] = 7;
        for(int i = 2; i <= 10; ++i) 
            dp[i] = 7 * (dp[i-1] + dp[i-2]);

        int arr[] = {0, 1, 2, 3, 5, 7, 8, 9};
        for(int i = 10; i >= 1; --i) {
            cout << arr[N / dp[i]];
            N %= dp[i];
        }
        cout << arr[N] << endl;
        */

        vector<int> digits;
        while(N) {
            digits.push_back(N % 8);
            N /= 8;
        }
        for(int i = digits.size()-1; i >= 0; --i) {
            cout << "01235789"[digits[i]];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
int table[] = {0, 1, 2, 3, 5, 7, 8, 9};
void ex(int n)
{
  if(n >= 8){
    ex(n / 8);
  }
  printf("%d", table[n % 8]);
}
int main()
{
  int n;
  while (cin >> n, n){
    ex(n);
    cout << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


// vector<ll> a(20,0);


int main(){
	ll n;
	char a[10]={'0','1','2','3','5','7','8','9'};
	while(cin>>n,n){
		string tmp2;
		string tmp1;
		stringstream ss1;
		ss1<<oct<<n;
		ss1>>tmp1;
		// cout<<tmp1<<endl;
		// const char tmp3[]=tmp1;
		// n=strtoul(tmp3,&tmp2,8);
		// string tmp;
		// stringstream ss;
		// ss>>tmp;
		rep(i,tmp1.size()){
			tmp1[i]=a[tmp1[i]-'0'];
		}
		cout<<tmp1<<endl;
	}

}

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

int main()
{
	const char* s = "01235789";
	int n;
	std::string ans;

	while( std::cin >> n, n )
	{
		ans.clear();

		while( n )
		{
			ans += s[n & 7];
			n >>= 3;
		}

		std::reverse( ans.begin(), ans.end() );
		std::cout << ans << std::endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	while(cin >> n,n){
		deque<int> va;
		while(n){
			va.push_front(n%8);
			n=n/8;
		}
		for(int i=0;i<va.size();i++){
			if(va[i]==4)va[i]++;
			else if(va[i]==5)va[i]+=2;
			else if(va[i]==6)va[i]+=2;
			else if(va[i]==7)va[i]+=2;
			cout << va[i];
		}
		cout << endl;
	}
	return 0;
}