Big Exponential Addition
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的更多相关文章
- Error Retries and Exponential Backoff in AWS
Error Retries and Exponential Backoff in AWS https://docs.aws.amazon.com/general/latest/gr/api-retri ...
- [LeetCode] Range Addition 范围相加
Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...
- iOS 之 SVN提交错误:"XXX" is scheduled for addition, but is missing
今天使用SVN提交项目时,出现了这样的提示:"XXX" is scheduled for addition, but is missing.(无关紧要的东西用XXX代替). 看报错 ...
- 基本概率分布Basic Concept of Probability Distributions 6: Exponential Distribution
PDF version PDF & CDF The exponential probability density function (PDF) is $$f(x; \lambda) = \b ...
- [20160704]Addition program that use JOptionPane for input and output
//Addition program that use JOptionPane for input and output. import javax.swing.JOptionPane; public ...
- in addition to 和 except for
except for 除了...以外(与 except for 连用的整体词与 except for 所跟的词往往不是同类的,是指整体中除去 一个细节.) eg:Your composition is ...
- [MCSM]Exponential family: 指数分布族
Exponential family(指数分布族)是一个经常出现的概念,但是对其定义并不是特别的清晰,今天好好看了看WIKI上的内容,有了一个大致的了解,先和大家分享下.本文基本是WIKI上部分内容的 ...
- Project Euler 99:Largest exponential 最大的幂
Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...
- UVALive 7324 ASCII Addition (模拟)
ASCII Addition 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/A Description Nowadays, th ...
- EMA计算的C#实现(c# Exponential Moving Average (EMA) indicator )
原来国外有个源码(TechnicalAnalysisEngine src 1.25)内部对EMA的计算是: var copyInputValues = input.ToList(); for (int ...
随机推荐
- 友盟+U-APM 移动应用性能体验报告:Android崩溃率达0.32%,OPPO 、华为、VIVO 崩溃表现良好
简介: 应用性能稳定是良好用户体验中非常关键的一环,而现实情况却是应用崩溃.卡顿.加载缓慢.页面白屏等问题,频频出现在用户的真实体验之中,成为影响业务表现的直接杀手.为此,应用性能管理(APM)正在国 ...
- [FE] ServerSideRender 加上 PWA 特性的一种处理方式
SSR 和 PWA 这两块分开讲,需要做不少的处理,现在我们有了一种简便的方式来处理它,就是使用 Quasar 框架. Quasar 支持了 SPA.SSR.PWA.Mobile APP.Electr ...
- [FAQ] Error: Component series.bar not exists. Load it first. (echarts)
以上错误出现在使用 echarts 组件时,未导入或者使用不正确的情况下. 检查是否导入 line 或者 bar 这一类具体的 chart,比如: import 'echarts/lib/chart/ ...
- [Go] 浅谈 Golang struct 与 PHP class 的相似
Golang 中的 struct 与 PHP 的 class 在使用方式上差不多. struct 中的成员可以类比 class 中的属性,struct 中的成员函数可以类比 class 中的方法. 对 ...
- dotnet 读 WPF 源代码笔记 为什么加上 BooleanBoxes 类
在 WPF 框架,为什么需要定义一个 BooleanBoxes 类.为什么在 D3DImage 的 Callback 方法里面,传入的是 object 对象,却能被转换为布尔.本文将告诉大家为什么需要 ...
- iptables命令详解
安装iptables yum install iptables-services 编写允许访问的策略 vim /etc/sysconfig/iptables # sample configuratio ...
- 在Deepin 20.2系统中换源并全新图解安装MySQL数据库
在Deepin 20.2系统中换源并全新图解安装MySQL数据库 https://www.ywnz.com/linuxysjk/9249.html ubuntu下apt-get彻底卸载mysql 删除 ...
- nmcli device status状态为unmanaged
遇到报错:(device lo not available because device is strictly unmanaged) nmcli device status 查看设备状态 nmcli ...
- blocks (单调栈)
题目描述 解析 对于这道题,他要求大于k的数进行操作,所以直接让每个数减k,然后用前缀和维护一下与0比较就可以了,因为一段区间和的平 均值大于k的话,那么这就是一个合法区间,即为操作后的这个区间和大于 ...
- MyBatis-Plus 实现多租户管理的实践
本文主要讲解使用Mybatis-Plus结合dynamic-datasource来实现多租户管理 在现代企业应用中,多租户(Multi-Tenant)架构已经成为一个非常重要的设计模式.多租户架构允许 ...