当前位置:网站首页>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();
}
}
边栏推荐
- YOLOv5s-ShuffleNetV2
- How to use async Awati asynchronous task processing instead of backgroundworker?
- 矩阵翻转(数组模拟)
- 测试工程师如何“攻城”(下)
- prometheus安装
- Shell programming core technology "I"
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- 在线SQL转Excel(xls/xlsx)工具
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
猜你喜欢
How to use async Awati asynchronous task processing instead of backgroundworker?
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
线上数据库迁移的几种方法
Oracle with as ora-00903: invalid table name multi report error
Use canal and rocketmq to listen to MySQL binlog logs
C# 使用StopWatch测量程序运行时间
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
如何使用Async-Awati异步任務處理代替BackgroundWorker?
随机推荐
Technologie de base de la programmation Shell IV
牛客小白月赛7 谁是神箭手
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
使用canal配合rocketmq监听mysql的binlog日志
Don't just learn Oracle and MySQL!
26. 删除有序数组中的重复项 C#解答
LM10丨余弦波动顺势网格策略
node_exporter部署
Pytest 可视化测试报告之 Allure
一文掌握数仓中auto analyze的使用
@transactional滥用导致数据源连接池耗尽问题
偏移量函数及开窗函数
Bi skills - permission axis
Have you guys ever used CDC direct Mysql to Clickhouse
《工作、消费主义和新穷人》的微信读书笔记
Double colon function operator and namespace explanation
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
How test engineers "attack the city" (Part I)
To sort out messy header files, I use include what you use
Jetpack Compose 教程