[题解]计算2的N次方(误)

Author Avatar
黎明余光 2017年07月02日
  • 在其它设备中阅读本文章

OpenJudge 上看到这么一道普通的高精度题

任意给定一个正整数 N(N<=100),计算 2 的 n 次方的值。

随便翻讨论发现有人 用 Pascal 穷举 还 AC 了
当然要用 CPP 玩一玩啊对吧 hhhh
(这段代码当然不是手写的,用 PHP 直接处理了一下 Pascal 的代码

# include <iostream>

using namespace std;

int main() {
    int n;
    cin>>n;
    switch(n) {
        case 1:
            cout<<"2";
            break;
        case 2:
            cout<<"4";
            break;
        case 3:
            cout<<"8";
            break;
        case 4:
            cout<<"16";
            break;
        case 5:
            cout<<"32";
            break;
        case 6:
            cout<<"64";
            break;
        case 7:
            cout<<"128";
            break;
        case 8:
            cout<<"256";
            break;
        case 9:
            cout<<"512";
            break;
        case 10:
            cout<<"1024";
            break;
        case 11:
            cout<<"2048";
            break;
        case 12:
            cout<<"4096";
            break;
        case 13:
            cout<<"8192";
            break;
        case 14:
            cout<<"16384";
            break;
        case 15:
            cout<<"32768";
            break;
        case 16:
            cout<<"65536";
            break;
        case 17:
            cout<<"131072";
            break;
        case 18:
            cout<<"262144";
            break;
        case 19:
            cout<<"524288";
            break;
        case 20:
            cout<<"1048576";
            break;
        case 21:
            cout<<"2097152";
            break;
        case 22:
            cout<<"4194304";
            break;
        case 23:
            cout<<"8388608";
            break;
        case 24:
            cout<<"16777216";
            break;
        case 25:
            cout<<"33554432";
            break;
        case 26:
            cout<<"67108864";
            break;
        case 27:
            cout<<"134217728";
            break;
        case 28:
            cout<<"268435456";
            break;
        case 29:
            cout<<"536870912";
            break;
        case 30:
            cout<<"1073741824";
            break;
        case 31:
            cout<<"2147483648";
            break;
        case 32:
            cout<<"4294967296";
            break;
        case 33:
            cout<<"8589934592";
            break;
        case 34:
            cout<<"17179869184";
            break;
        case 35:
            cout<<"34359738368";
            break;
        case 36:
            cout<<"68719476736";
            break;
        case 37:
            cout<<"137438953472";
            break;
        case 38:
            cout<<"274877906944";
            break;
        case 39:
            cout<<"549755813888";
            break;
        case 40:
            cout<<"1099511627776";
            break;
        case 41:
            cout<<"2199023255552";
            break;
        case 42:
            cout<<"4398046511104";
            break;
        case 43:
            cout<<"8796093022208";
            break;
        case 44:
            cout<<"17592186044416";
            break;
        case 45:
            cout<<"35184372088832";
            break;
        case 46:
            cout<<"70368744177664";
            break;
        case 47:
            cout<<"140737488355328";
            break;
        case 48:
            cout<<"281474976710656";
            break;
        case 49:
            cout<<"562949953421312";
            break;
        case 50:
            cout<<"1125899906842624";
            break;
        case 51:
            cout<<"2251799813685248";
            break;
        case 52:
            cout<<"4503599627370496";
            break;
        case 53:
            cout<<"9007199254740992";
            break;
        case 54:
            cout<<"18014398509481984";
            break;
        case 55:
            cout<<"36028797018963968";
            break;
        case 56:
            cout<<"72057594037927936";
            break;
        case 57:
            cout<<"144115188075855872";
            break;
        case 58:
            cout<<"288230376151711744";
            break;
        case 59:
            cout<<"576460752303423488";
            break;
        case 60:
            cout<<"1152921504606846976";
            break;
        case 61:
            cout<<"2305843009213693952";
            break;
        case 62:
            cout<<"4611686018427387904";
            break;
        case 63:
            cout<<"9223372036854775808";
            break;
        case 64:
            cout<<"18446744073709551616";
            break;
        case 65:
            cout<<"36893488147419103232";
            break;
        case 66:
            cout<<"73786976294838206464";
            break;
        case 67:
            cout<<"147573952589676412928";
            break;
        case 68:
            cout<<"295147905179352825856";
            break;
        case 69:
            cout<<"590295810358705651712";
            break;
        case 70:
            cout<<"1180591620717411303424";
            break;
        case 71:
            cout<<"2361183241434822606848";
            break;
        case 72:
            cout<<"4722366482869645213696";
            break;
        case 73:
            cout<<"9444732965739290427392";
            break;
        case 74:
            cout<<"18889465931478580854784";
            break;
        case 75:
            cout<<"37778931862957161709568";
            break;
        case 76:
            cout<<"75557863725914323419136";
            break;
        case 77:
            cout<<"151115727451828646838272";
            break;
        case 78:
            cout<<"302231454903657293676544";
            break;
        case 79:
            cout<<"604462909807314587353088";
            break;
        case 80:
            cout<<"1208925819614629174706176";
            break;
        case 81:
            cout<<"2417851639229258349412352";
            break;
        case 82:
            cout<<"4835703278458516698824704";
            break;
        case 83:
            cout<<"9671406556917033397649408";
            break;
        case 84:
            cout<<"19342813113834066795298816";
            break;
        case 85:
            cout<<"38685626227668133590597632";
            break;
        case 86:
            cout<<"77371252455336267181195264";
            break;
        case 87:
            cout<<"154742504910672534362390528";
            break;
        case 88:
            cout<<"309485009821345068724781056";
            break;
        case 89:
            cout<<"618970019642690137449562112";
            break;
        case 90:
            cout<<"1237940039285380274899124224";
            break;
        case 91:
            cout<<"2475880078570760549798248448";
            break;
        case 92:
            cout<<"4951760157141521099596496896";
            break;
        case 93:
            cout<<"9903520314283042199192993792";
            break;
        case 94:
            cout<<"19807040628566084398385987584";
            break;
        case 95:
            cout<<"39614081257132168796771975168";
            break;
        case 96:
            cout<<"79228162514264337593543950336";
            break;
        case 97:
            cout<<"158456325028528675187087900672";
            break;
        case 98:
            cout<<"316912650057057350374175801344";
            break;
        case 99:
            cout<<"633825300114114700748351602688";
            break;
        case 100:
            cout<<"1267650600228229401496703205376";
            break;
    }
    return 0;
}

保证 AC (逃
其实下面这首歌才是重点

本文链接:https://blog.lim-light.com/archives/cpp-2-n.html
本文采用 CC BY-NC-SA 3.0 CN 协议进行许可,阅读 相关说明