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 <cstdio>

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

int b;

long long retans(int bef){
  if(bef < 8){
    return a[bef];
  }else{
    long long ans = a[bef % 8];
    ans += retans(bef / 8) * 10;
    return ans;
  }
}

int main(){
  for(;;){
    scanf("%d", &b);
    if(b == 0){
      break;
    }else{
      long long pri = retans(b);
      printf("%lld\n", pri);
    }
  }
}

C++: #include<iostream>
#define len 12

using namespace std;

char num[12];
int in;

int main () {

  while ( true ) {
    cin >> in;

    if ( in == 0 )
      break;

    for ( int i=11; i>=0; i-- ) {
      num[i] = (in & 7) + '0';
      //num[i] = in%8+'0';
      in = in>>3;
    }
  
    int count = 0;
    while ( num[count] == '0' )
      count++;
  

    for ( int i=count;i <len; i++ ) {
      if ( num[i] == '4' )
	cout << '5';
      else if ( num[i] >'4' )
	cout << (char)(num[i]+2);
      else
	cout << num[i];
    }
    cout << endl;
  }

}

C++: #include<cstdio>
int f(int n){if(n)f(n/8),putchar("01235789"[n&7]);}
main(){for(int n;scanf("%d",&n),n;puts(""))f(n);}

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

const string digit = "01235789";

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> v;
        int t = n;
        while (t) {
            v.push_back(t % 8);
            t /= 8;
        }
        string res = "";
        for (int i=0; i<(int)v.size(); ++i) {
            res = digit[v[i]] + res;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

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

void solve(int n){
    
    if(n >= 8){
        solve(n / 8);
    }
    
    printf("%d", table[n % 8]);
}

int main(){
    int n;
    
    while(scanf("%d", &n), n > 0){
        solve(n);
        printf("\n");
    }
    
    return 0;
}

C++: #include <iostream>

using namespace std;
 
int main()
{
    int room[8] = {0, 1, 2, 3, 5, 7, 8, 9}, n;
    int newroom[10], i;
     
    while (cin >> n, n) {
        for (i = 0; ;i++) {
            int nn = n / 8;
            newroom[i] = n % 8;
            n = nn;
            if (!n) break;
        }    
        for (int j = i; j >= 0; j--) {
            cout << room[newroom[j]];
        }
        cout << endl;
    }    
    return 0;
}

C++: #include <cstdio>
#include <stdlib.h>
#include <cstring>


using namespace std;

int main(void){
	int i, n;
	char ans[128];
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		sprintf(ans,"%o",n);
		for(i = 0;i < strlen(ans);i++){
			if(ans[i] >= '5'){
				ans[i] += 2;
			}else if(ans[i] == '4'){
				ans[i]++;
			}
		}
		printf("%s\n",ans);
	}
	return 0;
}

C++: #include <stdio.h>
 
int main(void) {
	int i;
char ans[10];
while(scanf("%d",&i),i){
sprintf(ans,"%o",i);
for(i=0;i<10;i++){
if(ans[i]=='\0') break;
 
if(ans[i]>='4') ans[i]++;
if(ans[i]>='6') ans[i]++;
 
}
printf("%s\n",ans);
}
	return 0;
}

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

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

int main()
{
  vector<int> num;
  int n;
  while (scanf("%d ", &n) == 1) {
    if (n == 0) {break;}
    num.clear();
    while (n > 0) {
      num.push_back(n % 8);
      n /= 8;
    }
    reverse(num.begin(), num.end());
    for (int i = 0; i < num.size(); i++) {
      printf("%d", table[num[i]]);
    }
    printf("\n");
  }
  return 0;
}

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

int convert(int n){
	static int c[8]={0,1,2,3,5,7,8,9};
	return c[n];
}
int main(){
	int n;
	vector<int> v;
	vector<int>::reverse_iterator i;
	while(cin>>n,n){
		v.clear();
		while(n){
			v.push_back(convert(n%8));
			n/=8;
		}
		for(i=v.rbegin();i!=v.rend();++i)
			cout<<*i;
		cout<<endl;
	}
}

C++: #include<iostream>

typedef unsigned long long ll;

int main(){
	ll n;
	while (1){
		std::cin >> n;
		if (n == 0)break;
		unsigned long long a = 0;
		ll ans;
		for (ll i = 1; i < 1000000001; ++i){
			
			ll i_ = i;
			bool f = false;
			while (i_>0){
				if (i_ % 10 == 4 || i % 10 == 6){
					f = true;
					break;
				}
				i_ /= 10;
			}
			if (f)continue;
			a++;
			if (n == a){
				ans = i;
				break;
			}
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

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

int main(){
	int input;
	char num[10];
	while(cin >> input, input){
		sprintf(num, "%o", input);

		for(int i=0; i < 10; i++){
			if(num[i] == '4') num[i] = '5';
			else if(num[i] < '4') continue;
			else num[i] += 2;
		}
		cout << num << endl;
	}
}

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

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

//特別な8進数に変換する
//８進数に変換する方法だが、コンピュータシステム概論で１０進数を２進数になおした時の様に
//８で割ったときのあまりが８より小さくなるまでわっていく
//８でわれなくなったとき、そののこったのから上にもどしていく
//うまくかけないので、コンピュータシステム概論のハンドアウトを読んでたも

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 <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef long long ll;

int main() {
  ll n;
  while(cin>>n,n) {
    string oct;
    while (n != 0) {
      oct = string(1,'0'+n%8) + oct;
      n /= 8;
    }
    FOR(it, oct) {
      if (*it >= '5')
        (*it)++;
      if (*it >= '4')
        (*it)++;
    }
    cout << oct << endl;
  }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

static const char *s = "01235789";

main {
  int n;
  while (cin >> n, n) {
    string t;
    for (; n; n /= 8) t = string(1, s[n % 8]) + t;
    cout << t << endl;
  }
}