C++
$\color{gold}{— > 蓝桥杯辅导课题解}$
思路:
思维
$\color{#ff00ff}{图解分析:}$
由此:
当选x个砝码时,f(x)为能称的最大重量,有:
$f(x) = f(x-1)*3+1$
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n; cin >> n;
ll f = 0, x = 0;
while (1) {
if (f >= n) break;
f = f * 3 + 1;
x ++;
}
cout << x;
return 0;
}