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

int main(){
	
	char ch[8] = {'0', '1', '2', '3', '5', '7', '8', '9'};
	int n;
	
	while( cin >> n, n ){
		string s;
		do{
			s.push_back( ch[n % 8] );
			n /= 8;
		}while( n > 0 );
		reverse( s.begin() , s.end() );
		cout << s << endl;
	}
}

C++: #include<iostream>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		int g=0;
		for(int i=0;i<a;i++){
			g++;
			int n=10;
			for(int i=1;i<10;i++){
				if(g%n==4||g%n==6||g/n==4||g/n==6)g++;
				n*=10;
			}
		}
		std::cout<<g<<std::endl;
		}
		std::system("pause");
		return 0;
	}

C++: #include <iostream>
using namespace std;
int  main(){char s[]={'0','1','2','3','5','7','8','9'};int n;for(;cin>>n,n;cout<<a<<endl)for(string a="";n>0;n/=8)a=s[n%8]+a;}

C++: // 2011/08/09 Tazoe

#include <iostream>
using namespace std;

void radix(int n)
{
	if(n==0)
		return;

	radix(n/8);

	switch(n%8){
		case 0:
			cout << 0;
			break;
		case 1:
			cout << 1;
			break;
		case 2:
			cout << 2;
			break;
		case 3:
			cout << 3;
			break;
		case 4:
			cout << 5;
			break;
		case 5:
			cout << 7;
			break;
		case 6:
			cout << 8;
			break;
		case 7:
			cout << 9;
			break;
	}
}

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

		radix(n);
		cout << endl;
	}

	return 0;
}

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


long long int d8(long long int c, int n, int d)
{
	int r2 = n % 8;
	if (r2 > 4) r2++;
	if (r2 > 3) r2++;
	c += r2 * pow(10,d - 1);
	if (n / 8 > 0)
		c = d8(c, n / 8, d + 1);
	
	return c;
}

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		cout << d8(0, n, 1) << endl;
	}

	return 0;
}

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

static const std::vector<int> map{ 0, 1, 2, 3, 5, 7, 8, 9 };
void oct(const int &num) {
	if (num != 0) {
		oct(num / 8);
		std::cout << map.at(num % 8);
	}
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		oct(n);
		std::cout << "\n";
		std::cin >> n;
	}
}

C++: #include <cstdio>
int m[]={0,1,2,3,5,7,8,9},n;
char b[16],*c;
int main(){while(scanf("%d",&n),n){sprintf(b,"%o",n);for(c=b;*c;c++)putchar(m[*c-'0']+'0');puts("");}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 <= 100000; 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+=100000;
			if(cnum>n)
				break;
			int ret=fourOrSixPlace(cnum);
			if(ret==-1){
				//				cnt+=32769;
				n+=67232;
			}
			else{
				n+=67232;
				cnum+=(ll)pow(10.0,ret);
				n+=(ll)pow(10.0,ret);
			}
		}
		if(cnum==n){
			cout<<n<<endl;
		}
		else{
			cnum-=100000;
			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);
					}
				}
			}
		}


		//int cnt=0;
		cout<<n<<endl;
	}

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

	//}

	return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208

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

int div(int n) {
	if (n >= 8) div(n / 8);
	cout << d[n % 8];
}

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

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

int main(void){
  int num[] = {0,1,2,3,5,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<iostream>

int n;
int pw[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

void solve(){
	unsigned long long ans = 0;
	int tmp = n;
	for(int i=0; i<10; i++){
		int temp = tmp%8;
		if(temp==4)
			temp++;
		else if(temp > 4)
			temp+=2;
		ans += temp*pw[i];
		tmp = tmp/8;
		if(tmp == 0)
			break;
	}
	std::cout << ans << std::endl;
}

int main(){
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		solve();
	}
}

C++: #include <stdio.h>
const int a[8] = { 0, 1, 2, 3, 5, 7, 8, 9 };
int n;
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		bool flag = false;
		while(n != 0) {
			int val = n / 8;
			flag = flag || val;
			if(flag) {
				printf("%d", a[val]);
			}
			n /= 8;
		}
		printf("\n");
	}
	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(n/8);
  }
 return(table[n%8]);
 }
 int main()
 {
 int n;
 while(cin>>n, n>0)
 {
  surgeon(n);
  cout<<endl;
  }
 return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, num[100];
	while (cin >> n, n) {
		int k = -1;
		do {
			num[++k] = n % 8;
			if (num[k] >= 5) num[k] += 2;
			else if (num[k] >= 4) ++num[k];
		} while (n /= 8);
		for (int i = k; i >= 0; --i) cout << num[i];
		cout << endl;
	}
return 0;
}

C++: #include <iostream>
using namespace std;
int  main(){char s[]={48,49,50,51,53,55,56,57};int n;string a;for(;cin>>n,n;cout<<a<<endl)for(a="";n>0;n/=8)a=s[n%8]+a;}

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

int num(int x) {
	if (x == 4)return 5;
	else if (x > 4)return x + 2;
	else return x;
}

int main() {
	int n;
	while (cin >> n, n) {
		stack<int>st;
		while (n > 7) {
			int a = (n % 8);
			a = num(a);
			st.push(a);
			n /= 8;
		}
		st.push(n);

		int b = st.size();
		for (int i = 0;i < b;i++) {
			cout << st.top();
			st.pop();
		}
		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    string s = "";
    while (n) {
      s = to_string(n % 8) + s;
      n /= 8;
    }
    string ans = "";
    for (int i = 0; i < int(s.size()); i++) {
      if (s[i] <= '3') ans += s[i];
      else if (s[i] <= '4') ans += s[i] + 1;
      else ans += s[i] + 2;
    }
    cout << ans << endl;
  }  

  return 0;
}

C++: #include<iostream>

#define N 1000000000

using namespace std;

int data[N];

int check(int n, int keta){
  for(int i = 0; i < keta; i++){
    if(n%10 == 4 || n%10 == 6) return 0;
    n/=10;
  }
  return 1;
}

void make(){
  int num = 0;
  int keta = 1;

  for(int i = 0; i < N; i++){
    num++;
    if(num == 10) keta++;
    if(num == 100) keta++;
    if(num == 1000) keta++;
    if(num == 10000) keta++;
    if(num == 100000) keta++;
    if(num == 1000000) keta++;
    if(num == 10000000) keta++;
    if(num == 100000000) keta++;
    if(check(num,keta)) data[i] = num;
    else i--;
  }
}

int main(){
  make();
  int in;
  while(cin >> in && in) cout << data[in-1] << endl;
  return 0;
}