# 求十進制數n的 2至 n-1進制的表達

/*假設數爲num, 進製爲n */

vector<int> transform(int num, int n)
{
vector<int> list;
while (num != 0)
{
int a = num % n;
num = num / n;
list.push_back(a);
}

return list;

}

/*

*/

``````#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int transform(int num, int n)
{
vector<int> list;
int sum = 0;
while (num != 0)
{
int a = num % n;
num = num / n;
list.push_back(a);
}
for (int i = 0; i < list.size(); i++)
{
sum += list[i];
}
return sum;
}

int gcd(int m, int n)
{
int r = m % n;
while (r != 0)
{
m = n;
n = r;
r = m % n;
}
return n;
}

int main_04()
{
int A;
while (cin >> A)
{
int sum = 0, div = A - 2;
for (int i = 2; i < A; i++)
{
sum += transform(A, i);
}
cout << sum / gcd(sum, div) << "/" << div / gcd(sum, div) << endl;
}

return 0;
}``````

/*

*/

``````#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int f(int num, int n)
{
vector<int> list;
int sum = 0;
while (num != 0)
{
int a = num % n;
num = num / n;
list.push_back(a);
}
for (int i = 0; i < list.size(); i++)
{
sum += list[i];
}
return sum;
}

int main_05()
{
int A;
while (cin >> A)
{
int count = 0;
for (int i = 1; i <= A; i++)
{
if (f(i, 10) == f(i, 2))
{
//cout <<i<<"  "<< f(i, 10)
//		<<"  "<< f(i, 2) << endl;
count++;
}
}
cout << count << endl;
}
return 0;
}``````