当前位置:网站首页>求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();
}
}
边栏推荐
- An example of multi module collaboration based on NCF
- 偏移量函数及开窗函数
- Hough Transform 霍夫变换原理
- 性能优化之关键渲染路径
- 26. Delete the duplicate item C solution in the ordered array
- Don't just learn Oracle and MySQL!
- Go microservice (II) - detailed introduction to protobuf
- 勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
- How to use async Awati asynchronous task processing instead of backgroundworker?
- 国元期货是正规平台吗?在国元期货开户安全吗?
猜你喜欢
One question per day (2022-07-02) - Minimum refueling times
BI技巧丨权限轴
神经网络物联网应用技术就业前景【欢迎补充】
[uniapp] uniapp development app online Preview PDF file
Process of manually encrypt the mass-producing firmware and programming ESP devices
Hough transform Hough transform principle
Pytorch学习(四)
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
神经网络物联网平台搭建(物联网平台搭建实战教程)
升级智能开关,“零火版”、“单火”接线方式差异有多大?
随机推荐
Cache é JSON uses JSON adapters
Shell programming core technology "four"
测试工程师如何“攻城”(下)
876. Intermediate node of linked list
Oracle with as ora-00903: invalid table name multi report error
How test engineers "attack the city" (Part 2)
读写关闭的channel是啥后果?
《工作、消费主义和新穷人》的微信读书笔记
How test engineers "attack the city" (Part I)
2021 合肥市信息学竞赛小学组
ftp、sftp文件传输
2021 Hefei informatics competition primary school group
1008 Elevator(20 分)(PAT甲级)
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Caché WebSocket
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
升级智能开关,“零火版”、“单火”接线方式差异有多大?
QT realizes interface sliding switching effect
YOLOv5s-ShuffleNetV2