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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll calc(ll n, int digit) {
  assert(digit != 0);
  ll ret = 0;
  int d = n / digit;
  if (digit == 1) {
    if (d >= 6) { ret--; }
    if (d >= 4) { ret--; }
    ret += d + 1;
  } else {
    if (n / digit == 0) { return calc(n, digit / 10); }
    if (d == 4) {
      ret = 4 * calc(digit - 1, digit / 10);
    } else if (d == 6) {
      ret = 5 * calc(digit - 1, digit / 10);
    } else {
      if (d >= 6) { d -= 2; }
      else if (d >= 4) { d -= 1; }
      ret = d * calc(digit - 1, digit / 10);
      ret += calc(n % digit, digit / 10);
    }
  }
  return ret;
}

int main() {
  ll n;
  while (scanf("%lld", &n), n) {
    ll left = n;
    ll right = 10000000000LL;
    while (left != right) {
      ll mid = (left + right) / 2;
      if (calc(mid, 1000000000) - 1 < n) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
    printf("%lld\n", left);
  }
}

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

signed main() {
    while (true) {
        int n;
        cin >> n;
        
        if (n==0) {
            break;
        }
        
        map<int, int> mp{{0,0}, {1,1}, {2,2}, {3,3}, {4,5}, {5,7}, {6,8}, {7,9}};
        
        int ans = 0;
        int c = 1;
        
        while (!(n<8)) {
            ans += mp[n%8]*c;
            n /= 8;
            c *= 10;
        }
        
        ans += mp[n]*c;
        
        cout << ans << endl;
    }
}

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

int main()
{
	unsigned long long n, m;

	cin >> n;

	while (n) {
		m = 0;
		unsigned long long i = 1;

		while (n > 0) {
			unsigned long long t = n % 8;
			if (t < 4)
				m += t * i;
			else if (t == 4)
				m += 5 * i;
			else
				m += (t + 2) * i;

			n /= 8;
			i *= 10;
		}

		cout << m << endl;

		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

signed main() {
	//i?????? S????????? 4or6????????????
	int dp[12][2][2] = {};
	unordered_map<int, int> m;
	for (string S; cin >> S&&S != "0";) {
		string prev = "-1";
		m[stoll(prev)] = 0;
		while (prev != S) {
			memset(dp, 0, sizeof(dp));
			dp[0][0][0] = 1;
			rep(i, 0, S.size()) rep(j, 0, 2) rep(k, 0, 2) {
				int lim = j ? 9 : S[i] - '0';
				rep(d, 0, lim + 1) {
					//?????§??????????¢??????????????????????????¢????
					(dp[i + 1][j || d < lim][k || d == 4 || d == 6] += dp[i][j][k]);
				}
			}
			int s = m[stoll(prev)];
			prev = S;
			m[stoll(S)] = dp[S.size()][0][1] + dp[S.size()][1][1];
			S = to_string(stoll(S) + m[stoll(S)] - s);
			//dump(S);
		}
		cout << S << endl;
	}
	return 0;
}

C++: #include<cstdio>
int f(int n){if(n)f(n>>3),printf("%d",(n&7)+(n&4?n&3?2:1:0));}
int main(){int n;while(scanf("%d",&n),n)f(n),puts("");}

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

using namespace std;

int main() {

	long long int n, r;
	string s="";
	char x[sizeof(int)];

	while(cin >> n) {
		if(!n)
			break;
		r=0;
		
		for(int i=0; i<n; i++) {
			while(1) {
				r++;
				sprintf(x, "%d", r);
				if(!(strchr(x, '4')!=NULL)&&!(strchr(x, '6')!=NULL))
					break;
			}
		}
		cout << x << endl;
	}

	return 0;

}

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

int main()
{
	while(1){
		int a, j=0;
		cin >> a;
		j = a;
		string s="";
		int b = 0;
		for (b = 1; b * 8 <= a; b *= 8) {}
		for (int c = b; c != 1; c /= 8) {
			int o =a/c;
			switch (a / c) {
			case 0:case 1:case 2:case 3:cout << a / c;  break;
			case 4:cout << 5; break;
			default:cout << a / c + 2; break;
			}
			
			a -= c*o;
		}
			switch (j % 8) {
			case 0:case 1:case 2:case 3:cout << j % 8; break;
			case 4:cout << 5; break;
			default:cout << j % 8 + 2;
			}
		
		cout << endl;
			}
}

C++: #inmport<cstdio>
void s(int n){if(n>7)s(n/8);printf("%d",n%8<4?n%8:n%8<6?n%8+1:n%8+2);}main(){for(int a;scanf("%d",&a),a;puts(""))s(a);}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<char, int>P;

char buf[11];
int main(){
	int n;
	while (scanf("%d", &n), n) {
		sprintf(buf, "%o", n);
		rep(i, strlen(buf)) {
			if (buf[i] >= '5')buf[i] += 2;
			if (buf[i] == '4')buf[i]++;
		}
		printf("%s\n", buf);
	}
	return 0;
}

C++: 
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Stack;


class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){

		while(in.hasNext()){
			int n = in.nextInt();
			if(n == 0) return;
			System.out.println(toOct(n));
		}
		
	}

	String toOct(int n) {
		if(n == 0) return new String("0");
		StringBuilder ret = new StringBuilder();
		while(n > 0){
			int m = n % 8;
			if(m >= 4) m++;
			if(m > 5) m++;
			ret.append((char)('0' + m));
			n /= 8;
		}
		ret.reverse();
		return ret.toString();
	}

}

C++: #include <iostream>
using namespace std;
int main(){
	long long n,ans;
	int d[8]={0,1,2,3,5,7,8,9},tmp,f;
	while(cin>>n,n){
		ans=0;
		tmp=f=0;
		
		while(n>0){
			if(f){
				ans*=10;
				ans+=n%8;
				n/=8;
			}
			else{
				if(n%8==0)tmp++;
				else f=1;
				ans*=10;
				ans+=n%8;
				n/=8;
			}
		}
		for(;ans>0;ans/=10)cout<<d[ans%10];
		for(int i=0;i<tmp;i++)cout<<0;
		cout<<endl;
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

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

string f(ll n)
{
	string a;
	while(n)
	{
		if(n <= 8)
		{
			a += n + '0';
			break;
		}
		a += ex[n % 8] + '0';
		n /= 8;
	}
	reverse(a.begin(), a.end());

	return a;
}

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