当前位置:网站首页>求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();
}
}
边栏推荐
- Caché WebSocket
- 关于判断点是否位于轮廓内的一点思考
- LeetCode第300场周赛(20220703)
- Unity adds a function case similar to editor extension to its script, the use of ContextMenu
- 使用canal配合rocketmq监听mysql的binlog日志
- 神经网络物联网应用技术就业前景【欢迎补充】
- Build your own website (15)
- MySQL数据库基本操作-DDL | 黑马程序员
- Don't just learn Oracle and MySQL!
- Go微服务(二)——Protobuf详细入门
猜你喜欢

Stream流

PolyFit软件介绍

Nebula Importer 数据导入实践

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

Wireshark网络抓包

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

PointNeXt:通过改进的模型训练和缩放策略审视PointNet++

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

There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks

整理混乱的头文件,我用include what you use
随机推荐
千万不要只学 Oracle、MySQL!
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
Other InterSystems%net tools
PolyFit软件介绍
MySQL数据库基本操作-DDL | 黑马程序员
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Using SSH
IBM WebSphere MQ retrieving messages
2021 Hefei informatics competition primary school group
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
Have you guys ever used CDC direct Mysql to Clickhouse
Wireshark网络抓包
Shell programming core technology "four"
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
测试工程师如何“攻城”(上)
How to use async Awati asynchronous task processing instead of backgroundworker?
Oracle with as ORA-00903: invalid table name 多表报错
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
876. Intermediate node of linked list
Shell 編程核心技術《四》