当前位置:网站首页>求2的n次方
求2的n次方
2022-07-04 17:59:00 【相思明月楼】
方法一
这样最多可以计算出2的1000次方左右。
#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;
}
方法二
#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;
}
方法三
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();
}
}
边栏推荐
- MySQL数据库基本操作-DDL | 黑马程序员
- 与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
- 数组中的第K个最大元素
- SSL证书续费相关问题详解
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- Cache é JSON uses JSON adapters
- 国元期货是正规平台吗?在国元期货开户安全吗?
- Generate XML elements
- 页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
猜你喜欢
随机推荐
如何使用Async-Awati异步任務處理代替BackgroundWorker?
The kth largest element in the array
FPGA时序约束分享01_四大步骤简述
Pytest 可视化测试报告之 Allure
Other InterSystems%net tools
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
php伪原创api对接方法
牛客小白月赛7 I 新建 Microsoft Office Word 文档
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
一文掌握数仓中auto analyze的使用
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
神经网络物联网平台搭建(物联网平台搭建实战教程)
明明的随机数
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
Shell programming core technology II
Unity editor extends C to traverse all pictures in folders and subdirectories
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
In flinksql, in addition to data statistics, is the saved data itself a state
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题