Big Exponential Addition
给定一非负整数n计算2^n的值,一般而言把 2 乘上 n 次,就能得到答案。然而,当n特别大时,2^n要一次次地乘2可能稍嫌太慢,面对此一巨大问题利用分治(divide-and-conquer)演算法适当地拆解2 ^ n是个不错的策略,特别是在进行2^m + 2^n这类运算时,其效果更为明显。

INPUT
每一行有两非负整数,m与n 之间相隔一空白键。

OUTPUT
2^m + 2^n的精确值(每一笔输出在十进制2,000位以内),每个caes输出完毕後请输出一个换行字元做为区隔。

SAMPLE INPUT
3
12 13
20 14
140 115

SAMPLE OUTPUT
12288
1064960
1393796616446538814624603420284493227884544


答案

public class BigExponentialAddition {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
while(num>0){
int i = scan.nextInt();
int j = scan.nextInt();
System.out.println(bigExpoonential(i,j));
num--;
} }
public static BigInteger bigExpoonential(int i, int j) { int poor = Math.abs(i - j);
int minNum = 0;
BigInteger num_tow = BigInteger.valueOf(2);
minNum = i>j ? j : i;
return num_tow.pow(minNum).multiply(num_tow.pow(poor).add(BigInteger.valueOf(1)));
}
}

Big Exponential Addition的更多相关文章

  1. Error Retries and Exponential Backoff in AWS

    Error Retries and Exponential Backoff in AWS https://docs.aws.amazon.com/general/latest/gr/api-retri ...

  2. [LeetCode] Range Addition 范围相加

    Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...

  3. iOS 之 SVN提交错误:"XXX" is scheduled for addition, but is missing

    今天使用SVN提交项目时,出现了这样的提示:"XXX" is scheduled for addition, but is missing.(无关紧要的东西用XXX代替). 看报错 ...

  4. 基本概率分布Basic Concept of Probability Distributions 6: Exponential Distribution

    PDF version PDF & CDF The exponential probability density function (PDF) is $$f(x; \lambda) = \b ...

  5. [20160704]Addition program that use JOptionPane for input and output

    //Addition program that use JOptionPane for input and output. import javax.swing.JOptionPane; public ...

  6. in addition to 和 except for

    except for 除了...以外(与 except for 连用的整体词与 except for 所跟的词往往不是同类的,是指整体中除去 一个细节.) eg:Your composition is ...

  7. [MCSM]Exponential family: 指数分布族

    Exponential family(指数分布族)是一个经常出现的概念,但是对其定义并不是特别的清晰,今天好好看了看WIKI上的内容,有了一个大致的了解,先和大家分享下.本文基本是WIKI上部分内容的 ...

  8. Project Euler 99:Largest exponential 最大的幂

    Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...

  9. UVALive 7324 ASCII Addition (模拟)

    ASCII Addition 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/A Description Nowadays, th ...

  10. EMA计算的C#实现(c# Exponential Moving Average (EMA) indicator )

    原来国外有个源码(TechnicalAnalysisEngine src 1.25)内部对EMA的计算是: var copyInputValues = input.ToList(); for (int ...

随机推荐

  1. 阿里云CDN操控2.0版本正式发布

    ​简介: 2021年8月,阿里云边缘云CDN完成过去3年来最大的一次版本升级. 2021年8月,阿里云边缘云CDN完成过去3年来最大的一次版本升级.本次升级根据上万企业客户的使用反馈和行业应用特征,从 ...

  2. 庖丁解牛-图解MySQL 8.0优化器查询解析篇

    ​简介: SQL优化器本质上是一种高度抽象化的数据接口的实现,经过该设计,客户可以使用更通用且易于理解的SQL语言,对数据进行操作和处理,而不需要关注和抽象自己的数据接口,极大地解放了客户的应用程序. ...

  3. Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/xxx". at createRouterError 的说明和解决

    错误说明 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: & ...

  4. c#胖东来小程序自动购物程序(接单,windows桌面程序、linux程序、网络应用等等)

    一.程序效果 自动打开胖东来小程序,自动购物 二.实现 先截屏,然后利用opencv库识别下一步按键所在位置,然后使用mouse_event控制鼠标,模拟人的动作 第一步,截取屏幕 static Bi ...

  5. gprMax电磁波正演模拟方法

    文章首发于:https://blog.zhaoxuan.site/archives/37.html: 第一时间获取最新文章请关注博客个人站:https://blog.zhaoxuan.site. 目录 ...

  6. kibana-6.2.4-amd64的安装

    ubuntu系统 kibana: https://mirrors.huaweicloud.com/kibana/?C=N&O=D 找到6.2.4的下载连接 方法一: 下载tar包,解压即可: ...

  7. rails 写入日志函数

    json_object={ "ip"=> "127.0.0.1", "ports"=> '80,135', "data ...

  8. sh角本操作数据库

    #!/bin/bash HOST="127.0.0.1" PORT="3306" USERNAME="root" PASSWORD=&quo ...

  9. docker-compse 安装nginx 配置目录挂载

    一.新建一个启动服务的目录 mkdir /usr/local/docker/compose cd /usr/local/docker/compose 二.新建文件docker-compose.yml ...

  10. ansible(8)--ansible的hostname模块

    1. hostname模块 功能:管理远程主机的主机名. 示例一:更改192.168.20.22的主机名为nginx01: [root@xuzhichao ~]# ansible 192.168.20 ...