当前位置:网站首页>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();
}
}
边栏推荐
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- YOLOv5s-ShuffleNetV2
- 26. Delete the duplicate item C solution in the ordered array
- Unity editor extends C to traverse all pictures in folders and subdirectories
- Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- LM10丨余弦波动顺势网格策略
猜你喜欢

HMM隐马尔可夫模型最详细讲解与代码实现

SSRS筛选器的IN运算(即包含于)用法

勾股数规律(任意三个数能够满足勾股定理需要满足的条件)

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

更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?

用实际例子详细探究OpenCV的轮廓绘制函数drawContours()

在线文本行固定长度填充工具

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

如何使用Async-Awati异步任务处理代替BackgroundWorker?

Master the use of auto analyze in data warehouse
随机推荐
在线文本行固定长度填充工具
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
1003 Emergency(25 分)(PAT甲级)
牛客小白月赛7 E Applese的超能力
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
LeetCode 赎金信 C#解答
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
@transactional滥用导致数据源连接池耗尽问题
Have you guys ever used CDC direct Mysql to Clickhouse
1011 World Cup Betting (20 分)(PAT甲级)
牛客小白月赛7 F题
Summary and sorting of 8 pits of redis distributed lock
An example of multi module collaboration based on NCF
Shell 编程核心技术《四》
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
SSRS筛选器的IN运算(即包含于)用法
QT realizes interface sliding switching effect
1006 Sign In and Sign Out(25 分)(PAT甲级)