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>
#include<iostream>
using namespace std;

int main(void) 
{
	int a, b[] = { 0,1,2,3,5,7,8,9 };
	while (cin >> a)
	{
		if (a == 0)break;
		long long e = 1, ans = 0;
		while (a != 0)
		{
			int c = a % 8;
			ans += e * b[c];
			e *= 10;
			a /= 8;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

int main(){
	const char oct[] = {'0','1','2','3','5','7','8','9'};
	ll n;
	while(~scanf("%lld",&n)){
		if(n==0) break;
		char buf[11];
		sprintf(buf,"%llo",n);

		for(int i=10;i>=0;i--){
			if(buf[i]-'0' < 0 || buf[i]-'0' >= 8) continue;
			buf[i] = oct[buf[i]-'0'];
		}
		printf("%s",buf);
	}
}

C++: #include <stdio.h>
 
int main(void) {
	int i;
char ans[10];
while(scanf("%d",&i),i){
sprintf(a,"%o",i);
for(i=0;i<10;i++){
if(ans[i]>=4) ans[i]++;
if(ans[i]>=6) ans[i]++;
}
printf("%s\n",ans);
}
	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 <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;


int fourOrSixPlace(ll num){
	int idx=-1;
	int cnt=0;
	while(num>0){
		if(num%10==6||num%10==4){
			idx=cnt;
		}
		num/=10;
		cnt++;
	}
	return idx;
}

int main(){

	//int cc=0;
	//for(ll i = 1; i <= 10000; i++){
	//	int ret=fourOrSixPlace(i);
	//	if(ret!=-1)
	//		cc++;
	//}
	//cout<<cc<<endl;
	ll n;
	while(cin>>n&&n!=0){
		ll cnum=0;
		ll cnt=0;
		while(1){
			cnum+=10000;
			if(cnum>n)
				break;
			int ret=fourOrSixPlace(cnum);
			if(ret==-1){
				n+=5904;
			}
			else{
				n+=5904;
				cnum+=(ll)pow(10.0,ret);
				n+=(ll)pow(10.0,ret);
			}
		}
		if(cnum==n){
			cout<<n<<endl;
		}
		else{
			cnum-=10000;
			cnum++;
			for(ll i = cnum; i <= n; i++){
				int ret=fourOrSixPlace(i);
				if(ret!=-1){
					if(ret==0){
						n++;
					}
					else{
						n+=(ll)pow(10.0,ret);
						i+=(ll)pow(10.0,ret);
					}
				}
			}
		}
		cout<<n<<endl;
	}

	//ll n;
	//while(cin>>n&&n!=0){

	//}

	return 0;
}

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



int main() {
  long long n;
  int hex[] = {0, 1, 2, 3, 5, 7, 8, 9};
  while (cin >> n, n) {
    string res = "";
    while (n) {
      stringstream ss;
      ss << hex[n%8];
      res = ss.str() + res;
      n /= 8;
    }
    cout << res << endl;
  }
}

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<sstream>
#include<string>
using namespace std;

int main(){
	while(1){
		int n, ans = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = 0;i < n;i++){
			ans++;
			stringstream ss;
			ss << ans;
			string buf = ss.str();
			while(buf.find('4') != string::npos || buf.find('6') != string::npos){
				ans++;
				ss.str("");
				ss << ans;
				buf = ss.str();
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
  int num[] = {1,2,3,5,6,7,8,9};
  int n;
  while(cin>>n,n){
    long long a=0,d=1;
    while(n){
      a+=nums[n%8]*d;
      d*=10;
      n/=8;
    }	
    cout<<a<<endl;
  }
}

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

using namespace std;

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", pri);
    }
  }
}

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

vector<int> calc(int n) {
    vector<int> a;
    while (n > 0) {
        a.push_back(n % 8);
        n /= 8;
    }
    return a;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) return 0;

        vector<int> a = calc(n);
        for (int i = a.size() - 1; i >= 0; i--) {
            if (0 <= a[i] && a[i] <= 3) {
                cout << a[i];
            } else if (a[i] == 4) {
                cout << 5;
            } else {
                cout << a[i] + 2;
            }
        }
        cout << endl;
    }
}

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

using ll = long long;

int main() {
    int n;
    while(cin >> n, n) {
        string res;
        while(n > 0) {
            int oct = n & 7;
            if(oct <= 3) {
                res += '0' + oct;
            } else if(4 == oct) {
                res += '0' + oct + 1;
            } else {
                res += '0' + oct + 2;
            }
            n >>= 3;
        }
        reverse(res.begin(), res.end());
        cout << res << endl;
    }
}

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

string rec(int n) {
  if(n == 0) return "";
  int k = n % 8;
  return rec(n/8) + "01235789"[k];
}

int main() {
  int n;
  while(1) {
    cin >> n;
    if(n == 0) break;
    cout << rec(n) << endl;
  }

  return 0;
}