题解 | 跳台阶扩展问题

跳台阶扩展问题

https://www.nowcoder.com/practice/953b74ca5c4d44bb91f39ac4ddea0fee

//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
//  通过找规律也可以数学推,发现ans【n】 = 2 ^ (n - 1);
//  数据比较小快速幂写不写都行
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 1;
  int temp = 2;
  n--;
  while(n){
    if (n & 1){
      ans *= temp;
    }
    temp *= temp;
    n /= 2;
  }
  cout << ans;
}
// 64 位输出请用 printf("%lld")

#写题解领奖励##牛客春招刷题训练营#
全部评论

相关推荐

合适才能收到offe...:些许风霜罢了查看图片
点赞 评论 收藏
分享
Gardenia06...:刚开始学是这样的,可以看看左神和灵神都讲的不错
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务