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>

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,7,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>
using namespace std;

 const int table[] = { 1,2,3,4,5,6,7,8,9 };
 void surgeon(int x)
 {
  if(x>=8)
  {
  surgeon(x/8);
  }
 return(table[x%8]);
 }
 int main()
 {
 int x;
 while(cin>>x, x>0)
 {
  surgeon(x);
  cout<<endl;
  }
 return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	long long a[10], c = 1, d, e = 0;
	int b = 0;
	while (c <= 1000000000) {
		a[b] = c;
		b++;
		c *= 8;
	}
	while (cin >> d&&d != 0) {
		e = 0;
		int f = 0;
		for (int i = b-1; i >= 0; i--) {
			f = 0;
			if (a[i] <= d) {
				while (a[i] <= d) {
					f++;
					d -= a[i];
				}
				if (f <= 3)
					e += (pow(10, i)*f);
				else if (f == 5)
					e += (pow(10, i)*(f + 2));
				else if (f < 6)
					e += (pow(10, i)*(f + 1));
				else if(f>=6)
					e += (pow(10, i)*(f + 2));
			}
		}
		cout << e << endl;
	}
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        char octal[16] = {};
        sprintf(octal, "%o", n);
        for (int i = 0; octal[i] != '\0'; i++) {
            if (octal[i] == '4') {
                octal[i]++;
            } else if ('5' <= octal[i] && octal[i] <= '7') {
                octal[i] += 2;
            }
        }
        cout << octal << endl;
    }
}

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

int main() {
	vector<int> a;
	while(1) {
		int x = 0;
		scanf("%d", &x);
		a.push_back(x);
		if(x==0)break;
	}
	
	int l = a.size()-1;
	int b[l][10];
	
	for(int i=0;i<l;i++) {
		int a1 = a[i];
		for(int j=0;j<10;j++) {
			if(a1<1) {
				b[i][j] = -1;
			}else {
				int t = a1%8;
				if(t>3) {
					t++;
				}
				if(t>5) {
					t++;
				}
				b[i][j] = t;
				a1 /= 8;
			}
		}
	}
	
	for(int i=0;i<l;i++) {
		for(int j=9;j>=0;j--) {
			if(0<=b[i][j])printf("%d", b[i][j]);
		}
		printf("\n");
	}
	
	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+=num[n%8]*d;
      d*=10;
      n/=8;
    }	
    cout<<a<<endl;
  }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

vector<long long int>memo(20);
long long int getans(const long long  int n) {
	if (n <= 3)return n;
	else if (n == 4)return 5;
	else if (n <= 9)return n + 2;
	else {
		int keta;
		for (int i = 19; i >= 0; --i) {
			if (memo[i] < n) {
				keta = i;
				break;
			}
		}
		int num = n / memo[keta];
		if (num <= 3) {
			return powint(10, keta)*num + getans(n - memo[keta] * num);
		}
		else if (num == 4) {
			return powint(10, keta)*(num+1) + getans(n  - memo[keta] * num);
		}
		else {
			return powint(10, keta)*(num+2) + getans(n - memo[keta] * num);
		}

	}
}

int main() {
	memo[1] = 8;
	for (int i = 2; i < 20; ++i) {
		memo[i] = memo[i - 1] * 8;
	}
	while (1) {
		int N; cin >> N;
		if (!N)break;
		else {
			long long int ans = getans(N);
			cout << ans << endl;
		}

	}
	return 0;
}

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

int c[8] = {0, 1, 2, 3, 5, 7, 8, 9};
void solve(int n) {
  if(n >= 8) solve(n / 8);
  cout << c[n % 8];
}
int main() {
  int n;
  while(cin >> n, n) {
	solve(n);
	cout << "\n";
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

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

void f(int n)
{
	if(8 <= n) f(n / 8);
	cout << t[n%8];
}

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

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[]={0,1,2,3,5,7,8,9},n;
  while(cin>>n&&n){
    for(i=0;pow(8,i)<=n;i++);
    for(i--;i>=0;i--){
      cout<<a[n/(int)pow(8,i)];
      n%=(int)pow(8,i);
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>

bool func(unsigned long long int a);

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++;
			while(func(ans))ans++;
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

bool func(unsigned long long int a){
	while(a > 0){
		if(a % 10 == 4 || a % 10 == 6)return true;
		a /= 10;
	}
	return false;
}

C++: #include<stdio.h>
int f(long long n)
{
	while(n)
	{
		if(n%10==4||n%10==6) return 0;
		n/=10;
	}
	return 1;
}
int main()
{
	long long n,c,i;
	while(scanf("%lld",&n),n)
	{
		for(c=i=0;c<n;)
		{
			++i;
			if(f(i))
				++c;
		}
		printf("%lld\n",i);
	}
	return 0;
}