3 条题解

  • 4
    @ 2022-9-27 21:26:45

    1.高精度算法

    //定义和调用省略
    
    inline short reader(){
        //快读省略
    	return it ;
    }
    
    int main(){
        //cin >> n 
        //for(i - n) 也可以
    	for(int i = reader() ; i > 0 ; i --){
    		for(int j = 0 ; j <= xi ; j ++)
    			x[j] <<= 1 ;
            //x 乘二 可以使用左移
    		for(int j = 0 ; j <= xi ; j ++)
    			if(x[j] >= 10)
                //进位
    				x[j + 1] += x[j] / 10 ,
    				xi += (j == xi) ,//若是最后一位,则数的位数加一
    				x[j] %= 10 ;
    		for(int j = 0 ; j <= ai ; j ++){
    			al[j] += x[j] ;
                //每位加上x
    			if(al[j] >= 10)
                //进位
    				al[j + 1] += al[j] / 10 ,
    				ai += (j == ai) ,//若是最后一位,则数的位数加一
    				al[j] %= 10 ;
    		}
    	}
    	int i = ai ;
    	for(; i >= 0 ; i --)
    		putchar(al[i] + '0') ;
            //putchar输出,其他也可
    	return 0 ;
    }
    

    第二种,打表!

    #include <cstdio>
    #include <string>
    using std::string ;
    
    string a[101] ;
    
    void geter(){
    	a[1] = "2" , a[2] = "6" , a[3] = "14" , a[4] = "30" , a[5] = "62";
    	a[6] = "126" , a[7] = "254" , a[8] = "510" , a[9] = "1022" , a[10] = "2046";
    	a[11] = "4094" , a[12] = "8190" , a[13] = "16382" , a[14] = "32766" , a[15] = "65534";
    	a[16] = "131070" , a[17] = "262142" , a[18] = "524286" , a[19] = "1048574" , a[20] = "2097150";
    	a[21] = "4194302" , a[22] = "8388606" , a[23] = "16777214" , a[24] = "33554430" , a[25] = "67108862";
    	a[26] = "134217726" , a[27] = "268435454" , a[28] = "536870910" , a[29] = "1073741822" , a[30] = "2147483646";
    	a[31] = "4294967294" , a[32] = "8589934590" , a[33] = "17179869182" , a[34] = "34359738366" , a[35] = "68719476734";
    	a[36] = "137438953470" , a[37] = "274877906942" , a[38] = "549755813886" , a[39] = "1099511627774" , a[40] = "2199023255550";
    	a[41] = "4398046511102" , a[42] = "8796093022206" , a[43] = "17592186044414" , a[44] = "35184372088830" , a[45] = "70368744177662";
    	a[46] = "140737488355326" , a[47] = "281474976710654" , a[48] = "562949953421310" , a[49] = "1125899906842622" , a[50] = "2251799813685246";
    	a[51] = "4503599627370494" , a[52] = "9007199254740990" , a[53] = "18014398509481982" , a[54] = "36028797018963966" , a[55] = "72057594037927934";
    	a[56] = "144115188075855870" , a[57] = "288230376151711742" , a[58] = "576460752303423486" , a[59] = "1152921504606846974" , a[60] = "2305843009213693950";
    	a[61] = "4611686018427387902" , a[62] = "9223372036854775806" , a[63] = "18446744073709551614" , a[64] = "36893488147419103230" , a[65] = "73786976294838206462";
    	a[66] = "147573952589676412926" , a[67] = "295147905179352825854" , a[68] = "590295810358705651710" , a[69] = "1180591620717411303422" , a[70] = "2361183241434822606846";
    	a[71] = "4722366482869645213694" , a[72] = "9444732965739290427390" , a[73] = "18889465931478580854782" , a[74] = "37778931862957161709566" , a[75] = "75557863725914323419134";
    	a[76] = "151115727451828646838270" , a[77] = "302231454903657293676542" , a[78] = "604462909807314587353086" , a[79] = "1208925819614629174706174" , a[80] = "2417851639229258349412350";
    	a[81] = "4835703278458516698824702" , a[82] = "9671406556917033397649406" , a[83] = "19342813113834066795298814" , a[84] = "38685626227668133590597630" , a[85] = "77371252455336267181195262";;
    	a[86] = "154742504910672534362390526" , a[87] = "309485009821345068724781054" , a[88] = "618970019642690137449562110" , a[89] = "1237940039285380274899124222" , a[90] = "2475880078570760549798248446";
    	a[91] = "4951760157141521099596496894" , a[92] = "9903520314283042199192993790" , a[93] = "19807040628566084398385987582" , a[94] = "39614081257132168796771975166" , a[95] = "79228162514264337593543950334";
    	a[96] = "158456325028528675187087900670" , a[97] = "316912650057057350374175801342" , a[98] = "633825300114114700748351602686" , a[99] = "1267650600228229401496703205374" , a[100] = "2535301200456458802993406410750";
    }
    
    
    inline short reader(){
        
    }
    
    int main(){
    	geter() ;
    	printf("%s" , a[reader()].c_str()) ;
        /*
        //打表代码
        freopen("out.txt" , "w" , stdout) ;
    	for(int n = 1 ; n <= 100 ; n ++){
    		for(int i = 0 ; i < 40 ; i ++)
    			al[i] = x[i] = 0;
    		x[0] = 1 , xi = ai = 0 ;
    		printf("a[%d] = \"" , n) ;
    		for(int i = n ; i > 0 ; i --){
    			for(int j = 0 ; j <= xi ; j ++)
    				x[j] <<= 1 ;
    			for(int j = 0 ; j <= xi ; j ++)
    				if(x[j] >= 10)
    					x[j + 1] += x[j] / 10 ,
    					xi += (j == xi) ,
    					x[j] %= 10 ;
    			for(int j = 0 ; j <= ai ; j ++){
    				al[j] += x[j] ;
    				if(al[j] >= 10)
    					al[j + 1] += al[j] / 10 ,
    					ai += (j == ai) ,
    					al[j] %= 10 ;
    			}
    		}
    		int i = ai ;
    		for(; i >= 0 ; i --)
    			putchar(al[i] + '0') ;
    		printf("\"");
    		if(n % 5 == 0)
    			printf(";\n	") ;
    		else
    			printf(" , ") ;
    	}
        */
    	return 0 ;
    }
    
    • @ 2023-7-21 10:30:28

      兄弟TLE了啊

    • @ 2024-1-23 23:28:21

      我很好奇你那表是怎么算出来又不TLE的。 况且你真有这么大内存吗?

  • 1
    @ 2022-11-5 20:46:42

    嗨害嗨,我来了! 今天咱们讲讲2+2×2+……2×2×2……×2. 看到这题,楼下发话了:“打表不香么?” (真不错) 不不不,这也太low了! 各位,我向你们讲一个公式: Sn=2^(n+1)-2 (完爆打表者,等比数列求和了解一下) 好,上代码:

    a=input()
    a=int(a)
    p=2
    s=1
    for i in range(a+1):#2^(n+1)-2
        s *= 2
    print(s-2)#首项-末项
    

    Loading:12/100……

    • @ 2022-11-5 20:51:43

      这个方法证明很简单: 设S=2+2×2+……2×2×……×2 则2S=2×2+2×2×2+……2×2×……×2×2 2S-S=S=2+2×2+……2×2×……×2=2^(n+1)-2 即S=2+2×2+……2×2×……×2=2^(n+1)-2 这题采用这个方法,只需要13ms。

    • @ 2023-2-19 13:33:03

      q=2没用,直接删就行,a = int (input()),要节俭。

    • @ 2024-1-23 23:26:26

      python3是不是有点过分了?这里可是c++区! (虽然我也在用python

  • 0
    @ 2023-12-26 19:46:03
    #include <bits/stdc++.h>
    using namespace std;
    string add(string s,string b)
    {
    	long long t=0;
    	string res;
    	reverse(s.begin(),s.end());
    	reverse(b.begin(),b.end());
    	int len=max(s.size(),b.size());
    	for(int i=0;i<len;i++)
    	{
    		if(i<s.size()) t+=s[i]-'0';
    		if(i<b.size()) t+=b[i]-'0';
    		res+=(char)(t%10+'0');
    		t/=10;
    	}
    	if(t!=0) res+=(char)(t+'0');
    	reverse(res.begin(),res.end());
    	return res;
    }
    string mul(string s1,string s2)
    {
    	string ret;
    	int a[520]={0},b[520]={0},c[1020]={0};
    	int la=s1.length(),lb=s2.length();
    	for(int i=0;i<s1.length();i++)
    	{
    		a[s1.length()-i-1]=s1[i]-'0';
    	}
    	for(int i=0;i<s2.length();i++)
    	{
    		b[s2.length()-i-1]=s2[i]-'0';
    	}
    	for(int i=0;i<lb;i++)
    	{
    		for(int j=0;j<la;j++)
    		{
    			c[i+j]+=a[j]*b[i];
    			c[i+j+1]+=c[i+j]/10;
    			c[i+j]%=10;
    		}
    	}
    	int idx=la+lb;
    	while(idx&&!c[idx])
    	{
    		idx--;
    	}
    	for(int i=idx;i>=0;i--)
    	{
    		ret+=char(c[i]+'0');
    	}
    	return ret;
    }
    string sum="2";
    long long n; 
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	cin>>n;
        for(int i=2;i<=n;i++)
    	{
    		string s="2";
    		for(int j=1;j<=i-1;j++)
    		{
    			s=mul(s,"2");
    		}
    		sum=add(sum,s);
    	}
    	cout<<sum;
    	return 0;
    }
    
    • 1

    [普及~提高]求2+2*2+2*2*2+…+2*2*2*….*2

    信息

    ID
    279
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    241
    已通过
    53
    上传者