当前位置:网站首页>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();
}
}
边栏推荐
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- Qt实现界面滑动切换效果
- 勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
- Several methods of online database migration
- Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
- Pytorch学习(四)
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
- OpenCV的二值化处理函数threshold()详解
- 876. Intermediate node of linked list
- PolyFit软件介绍
猜你喜欢

C# 使用StopWatch测量程序运行时间

升级智能开关,“零火版”、“单火”接线方式差异有多大?
Summary and sorting of 8 pits of redis distributed lock

Go microservice (II) - detailed introduction to protobuf

92.(cesium篇)cesium楼栋分层

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

Oracle with as ORA-00903: invalid table name 多表报错

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

FPGA时序约束分享01_四大步骤简述

MySQL数据库基本操作-DDL | 黑马程序员
随机推荐
26. 删除有序数组中的重复项 C#解答
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
An example of multi module collaboration based on NCF
BI技巧丨权限轴
《工作、消费主义和新穷人》的微信读书笔记
The 300th weekly match of leetcode (20220703)
Technologie de base de la programmation Shell IV
socket编程demo二
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
1009 Product of Polynomials(25 分)(PAT甲级)
双冒号作用运算符以及命名空间详解
Functional interface
测试工程师如何“攻城”(下)
“只跑一趟”,小区装维任务主动推荐探索
C# 使用StopWatch测量程序运行时间
HDU 6440 2018中国大学生程序设计网络选拔赛
FPGA时序约束分享01_四大步骤简述
The 15th youth informatics competition in Shushan District in 2019
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用