题目来源:码蹄集
https://matiji.net/exam/brushquestion/286/778/B3FCFEC101BD05189BB74D522E019504
时间限制:1000ms
内存限制:65535kb
题目描述:如果一个数是7的幂,或者能分解成7的不同幂的和,那么这个数就叫做忠 实数。 例如49=49,8=1+7, 57=1+7+49。注意1可以看成7的0次方。 对忠实数进行从小到大排序得到的序列是1 7 8 49 50…等等。 输入正整数N,找到第N个忠实的数字。
输入格式:输入正整数N(<1000)
输出格式:输出整型
输入样例:7
输出样例:57
参考程序:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
ll nthFaithfulNum(int N) {
ll ans = 0;
ll base = 1;
while(N>0){
int last = N&1;
N = N>>1;
ans += last*base;
base = base*7;
}
return ans;
}
int main(){
ll n;
cin >> n;
cout << nthFaithfulNum(n);
return 0;
}