当前位置:网站首页>Find the nth power of 2
Find the nth power of 2
2022-07-04 19:36:00 【Acacia moon tower】
Method 1
In this way, at most 2 Of 1000 About the power .
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int n;
while(cin>>n) {
cout<<fixed<<setprecision(0)<<pow(2, n)<<endl;
}
return 0;
}
Method 2
#include <iostream>
int a[10001];
using namespace std;
int main() {
int i, j, x, len = 1, n;
cin>>n;
a[1] = 1;
for(i = 1; i <= n; i++) {
x = 0;
for(j = 1; j <= len; j++) {
a[j] = a[j]*2 + x;
x = a[j]/10;
a[j] %= 10;
if(x != 0 && j == len) len++;
}
}
for(i = len; i >= 1; i--)
cout<<a[i];
cout<<endl;
return 0;
}Method 3
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
for(int j = 0; j < a; j++) {
int n = in.nextInt();
BigInteger t = BigInteger.ONE;
for(int i = 1; i <= n; i++) {
t = t.multiply(BigInteger.valueOf(2));
}
System.out.println(t);
}
in.close();
}
}
边栏推荐
- 【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- Online sql to excel (xls/xlsx) tool
- prometheus安装
- Shell 编程核心技术《三》
- Qt实现界面滑动切换效果
- “只跑一趟”,小区装维任务主动推荐探索
- 1007 Maximum Subsequence Sum(25 分)(PAT甲级)
- Several methods of online database migration
- 92.(cesium篇)cesium楼栋分层
猜你喜欢

One question per day (2022-07-02) - Minimum refueling times

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

MySQL数据库基本操作-DDL | 黑马程序员

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

如何使用Async-Awati异步任務處理代替BackgroundWorker?

node_exporter部署
Some thoughts on whether the judgment point is located in the contour

How to use async Awati asynchronous task processing instead of backgroundworker?

Stream stream

Master the use of auto analyze in data warehouse
随机推荐
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Add namespace declaration
26. 删除有序数组中的重复项 C#解答
牛客小白月赛7 F题
Explicit random number
HDU 6440 2018中国大学生程序设计网络选拔赛
Have you guys ever used CDC direct Mysql to Clickhouse
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Shell programming core technology "four"
Double colon function operator and namespace explanation
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
To sort out messy header files, I use include what you use
Nebula importer data import practice
Detailed explanation of issues related to SSL certificate renewal
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
Lm10 cosine wave homeopathic grid strategy
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
Shell programming core technology "I"