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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef long long ll;

char i2c(int i) { return '0'+i; }

const char* d2o(ll a) {
  string s;
  while (a) {
    s += i2c(a % 8);
    a /= 8;
  }
  reverse(s.begin(), s.end());
  rep(i,s.size()) {
    if(s[i] == '4') s[i] = '5';
    else if(s[i] == '5') s[i] = '7';
    else if(s[i] == '6') s[i] = '8';
    else if(s[i] == '7') s[i] = '9';
  }
  return s.c_str();
}

int main() {
  //int in;
  ll in;
  while (cin>>in,in) {
    //printf("%d\n",in);
    //printf("%d\n",d2o(in));
    cout<<d2o(in)<<endl;
  }
  return 0;
}

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

int main()
 {
    int n;
    while(cin>>n,n)
    {
        int d[99]={0},c=0;
        while(n>0)
         {
            d[c++]=n%8;
            n/=8;
        }
        while(c--)
        cout<<"01235789"[d[c]];
        cout<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
char m[] = {'0','1','2','3','5','7','8','9'};
signed main(){
	int a;
	while( scanf("%lld", &a) != EOF ){
		if (a==0) break;
		vector<int> x(0,0);
		int l = 0;
		while(a>0){
			x.push_back(a%8);
			a/=8;
			l++;
		}
		for(unsigned int i=0;i<l;i++){
			cout << m[x[l-i-1]];
		}
		cout << endl;
	}
	return 0;
}

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=0; i<len; i++ ) {
      num[i] = 0;
    }

    for ( int i=11; i>=0; i-- ) {
      
      num[i] = in%8+'0';
      in = in/8;
    }
  
    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 <boost/format.hpp>

int main(){}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main(void)
{
	// itoa
	int n;
	while (cin >> n, n){
		char s[20];
		sprintf(s, "%o", n);
		
		string str = s;
		for (int i = 0; i < str.length(); i++){
			if ('4' <= str[i]) str[i]++;
			if ('6' <= str[i]) str[i]++;
		}
		cout << str << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define pb(c) push_back(c)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int getv(int x){
  if(x == 4) return 5;
  return (x < 4) ? x : x+2;
}

void convert(int n){
  if(n == 0) return;
  convert( n/8 );
  cout << getv(n%8);
}

int main(){
  ios::sync_with_stdio(false);
  int n;

  while(cin >> n && n){
    convert(n);
    cout << endl;
  }


}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    string s;
    char ss[256];
    sprintf(ss, "%o", n);
    s = ss;
    REP(i, s.size()){
      if (s[i] >= '4') s[i]++;
      if (s[i] >= '6') s[i]++;
    }
    print(s);
  }

  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 <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[1000000];
int main(){
	int n;
	while (scanf("%d", &n), n) {
		sprintf(buf, "%o", n);
		for (char&c : buf) {
			if (c >= '5')c += 2;
			if (c == '4')c++;
		}
		printf("%s\n", buf);
	}
	return 0;
}

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

using namespace std;


int main() {

  int n;

  char str[11];


  while(cin >> n) {

    if(n==0) break;

    sprintf(str,"%o",n);

    for(int i=0;i<11;i++) {

      if(str[i]=='4') str[i]='5';

      else if(str[i]>'4') str[i]+=2;

    }

    cout << str << endl;

  }
  
  return 0;

}

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

using namespace std;

int main(){
  long long int n;
  int i,c,r[11];
  int ei[8]={1,2,3,5,7,8,9,0};
  while(1){
    cin>>n;
    if(n==0)break;
    
    for(i=0;n>=8;i++){      
      r[i]=n%8;
      n/=8;
    }
    r[i]=n;
    for(;i>=0;i--){
      cout<<ei[r[i]-1];
    }
    cout<<endl; 
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
string s;
long dp[11][2][2];
main()
{
	long S;
	while(cin>>S,S)
	{
		long pre=0,ans=0;
		while(1)
		{
			s=to_string(S+=ans-pre);
			pre=ans;
			for(int i=0;i<=s.size();i++)for(int j=0;j<4;j++)dp[i][j/2][j%2]=0;
			dp[0][0][0]=1;
			for(int i=0;i<s.size();i++)
			{
				for(int j=0;j<2;j++)
				{
					for(int k=0;k<2;k++)
					{
						int lim=j?9:s[i]-'0';
						for(int l=0;l<=lim;l++)
						{
							dp[i+1][j||(l<lim)][k||(l==4||l==6)]+=dp[i][j][k];
						}
					}
				}
			}
			ans=dp[s.size()][0][1]+dp[s.size()][1][1];
			if(ans==pre)break;
		}
		cout<<S<<endl;
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		char str[16];
		sprintf(str, "%o", n);
		rep(i, strlen(str)){
			printf("%c", str[i] + (str[i]>='4') + (str[i]>='5'));
		}
		puts("");
	}
	
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int x[8] = { 0,1,2,3,5,7,8,9 };
int n, ok, k;
int main() {
	while (true) {
		ok = 0;
		cin >> n;
		if (!n) { break; }
		for (int i = 10; i >= 0; i--) {
			k = (n / (int)pow(8, i)) % 8;
			if (k > 0) { ok = 1; }
			if (ok == 1) { cout << x[k]; }
		}
		cout << endl;
	}
}

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

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

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

    vector<int> ans;
    while (n > 0) {
      ans.push_back(d2o[n%8]);
      n /= 8;
    }

    for (int i = ans.size()-1; i >= 0; --i)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}