当前位置:网站首页>求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();
}
}
边栏推荐
- One question per day (2022-07-02) - Minimum refueling times
- prometheus安装
- 《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
- 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
- 每日一题(2022-07-02)——最低加油次数
- 启牛开的证券账户安全吗?
- Is the securities account opened by qiniu safe?
- 26. Delete the duplicate item C solution in the ordered array
- 函数式接口
- PolyFit软件介绍
猜你喜欢

与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用

千万不要只学 Oracle、MySQL!

Oracle with as ora-00903: invalid table name multi report error

Pytorch学习(四)

Process of manually encrypt the mass-producing firmware and programming ESP devices

Nebula importer data import practice

Lm10 cosine wave homeopathic grid strategy

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

One question per day (2022-07-02) - Minimum refueling times
![[release] a tool for testing WebService and database connection - dbtest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)
[release] a tool for testing WebService and database connection - dbtest v1.0
随机推荐
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
测试工程师如何“攻城”(下)
《工作、消费主义和新穷人》的微信读书笔记
Shell 编程核心技术《二》
Jetpack Compose 教程
1006 Sign In and Sign Out(25 分)(PAT甲级)
The kth largest element in the array
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
Don't just learn Oracle and MySQL!
876. 链表的中间结点
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
Build your own website (15)
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
如何使用Async-Awati异步任务处理代替BackgroundWorker?
MySQL数据库基本操作-DDL | 黑马程序员
Qt实现界面滑动切换效果
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
[release] a tool for testing WebService and database connection - dbtest v1.0
php伪原创api对接方法
明明的随机数