using
System;
using
System.Collections.Generic;
class
GFG{
static
string
decToBin(
int
n)
{
if
(n == 0)
return
"0"
;
string
bin =
""
;
while
(n > 0)
{
bin = ((n & 1) == 0 ?
'0'
:
'1'
) + bin;
n >>= 1;
}
return
bin;
}
static
string
convertBinToOct(
string
bin)
{
int
l = bin.Length;
for
(
int
j = 1; j <= (3 - l % 3) % 3; j++)
bin =
'0'
+ bin;
Dictionary<
string
,
char
> bin_oct_map =
new
Dictionary<
string
,
char
>();
bin_oct_map.Add(
"000"
,
'0'
);
bin_oct_map.Add(
"001"
,
'1'
);
bin_oct_map.Add(
"010"
,
'2'
);
bin_oct_map.Add(
"011"
,
'3'
);
bin_oct_map.Add(
"100"
,
'4'
);
bin_oct_map.Add(
"101"
,
'5'
);
bin_oct_map.Add(
"110"
,
'6'
);
bin_oct_map.Add(
"111"
,
'7'
);
int
i = 0;
string
octal =
""
;
while
(
true
)
{
octal += bin_oct_map[bin.Substring(i, 3)];
i += 3;
if
(i == bin.Length)
break
;
}
return
octal;
}
static
string
decToOctal(
int
n)
{
string
bin = decToBin(n);
return
convertBinToOct(bin);
}
public
static
void
Main(
string
[] args)
{
int
n = 151;
Console.Write(decToOctal(n));
}
}