题解 | #扭蛋机#
扭蛋机
https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7
#include<bits/stdc++.h>
using namespace std;
%画出图发现N为偶数的时候,都是3,为奇数的时候都是2扭出来的,并且往前找的时候发现都是2倍关系,把每一次都当做N,从后往前寻找,然后再从后往前输出,
int main() {
int N;
cin >> N;
string str;
while(N > 0)
{
if(N % 2 == 1)
{
str += "2";
N = N / 2;
}
else
{
str += "3";
N = N/2-1;
}
}
for(int i = str.length()-1; i >= 0; i--)
{
cout<<str[i];
}
cout<<endl;
}
// 64 位输出请用 printf("%lld")
查看1道真题和解析
