当前位置:网站首页>求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();
}
}
边栏推荐
- 牛客小白月赛7 谁是神箭手
- 1672. 最富有客户的资产总量
- Shell 編程核心技術《四》
- 用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
- Shell 编程核心技术《三》
- The kth largest element in the array
- 2022养生展,健康展,北京大健康展,健康产业展11月举办
- 2021 Hefei informatics competition primary school group
- The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
- Nebula importer data import practice
猜你喜欢
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
从实时应用角度谈通信总线仲裁机制和网络流控
Online sql to excel (xls/xlsx) tool
Nebula importer data import practice
Oracle with as ORA-00903: invalid table name 多表报错
自由小兵儿
BI技巧丨权限轴
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Lm10 cosine wave homeopathic grid strategy
神经网络物联网平台搭建(物联网平台搭建实战教程)
随机推荐
The 15th youth informatics competition in Shushan District in 2019
Use canal and rocketmq to listen to MySQL binlog logs
Wireshark网络抓包
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
Using FTP
Online sql to excel (xls/xlsx) tool
建立自己的网站(15)
Cache é JSON uses JSON adapters
In flinksql, in addition to data statistics, is the saved data itself a state
Send and receive IBM WebSphere MQ messages
生成XML元素
Oracle with as ora-00903: invalid table name multi report error
Go microservice (II) - detailed introduction to protobuf
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
DeFi生态NFT流动性挖矿系统开发搭建
千万不要只学 Oracle、MySQL!
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
如何使用Async-Awati异步任務處理代替BackgroundWorker?