zoukankan      html  css  js  c++  java
  • 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)));
        }
    }
  • 相关阅读:
    【题解】LOJ #6488 数表【FWT】
    【题解】[Comet OJ Contest #11 F] arewell【子集卷积】
    【CF757F】 Team Rocket Rises Again 【支配树】
    支配树学习笔记
    JS模拟实现题目(new debounce throwee 等)
    React生命周期
    js转义符
    CSS3中的transform转换属性
    animation动画
    flex
  • 原文地址:https://www.cnblogs.com/bmbi/p/5281534.html
Copyright © 2011-2022 走看看