当前位置:网站首页>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();
}
}
边栏推荐
- Use canal and rocketmq to listen to MySQL binlog logs
- Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
- 2019年蜀山区第十五届青少年信息学竞赛
- 2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
- One question per day (2022-07-02) - Minimum refueling times
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- Allure of pytest visual test report
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- 牛客小白月赛7 I 新建 Microsoft Office Word 文档
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
猜你喜欢
One question per day (2022-07-02) - Minimum refueling times
Nebula importer data import practice
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Master the use of auto analyze in data warehouse
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
“只跑一趟”,小区装维任务主动推荐探索
How to use async Awati asynchronous task processing instead of backgroundworker?
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
随机推荐
Shell programming core technology "four"
双冒号作用运算符以及命名空间详解
Shell 编程核心技术《三》
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
To sort out messy header files, I use include what you use
Online sql to excel (xls/xlsx) tool
Pytorch学习(四)
Functional interface
数组中的第K个最大元素
牛客小白月赛7 F题
长城证券开户安全吗 买股票怎么开户
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Summary and sorting of 8 pits of redis distributed lock
Pytest 可视化测试报告之 Allure
English语法_名词 - 使用
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
有关架构设计的个人思考(本文后续不断修改更新)
LeetCode第300场周赛(20220703)
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Shell programming core technology II