当前位置:网站首页>求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();
}
}
边栏推荐
猜你喜欢
随机推荐
Hough Transform 霍夫变换原理
Other InterSystems%net tools
Leetcode ransom letter C # answer
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
关于判断点是否位于轮廓内的一点思考
Cache é JSON uses JSON adapters
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
MySQL数据库基本操作-DDL | 黑马程序员
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
每日一题(2022-07-02)——最低加油次数
Shell 編程核心技術《四》
“只跑一趟”,小区装维任务主动推荐探索
Nebula importer data import practice
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
A method of using tree LSTM reinforcement learning for connection sequence selection
IBM WebSphere MQ retrieving messages
1006 Sign In and Sign Out(25 分)(PAT甲级)
小发猫物联网平台搭建与应用模型
反射(一)








