1 solutions

  • 0
    @ 2025-11-5 17:23:48

    C :

    #include<stdio.h>
    int main()
    {
    	int n,i,j=1,k=1,x[200000]={0,1},m;
    	for(i=2;i<=200000;i++)
    	{
    		m=2*x[j]+1;
    		n=4*x[k]+5;
    		if(m>n){x[i]=n;k++;}else{x[i]=m;j++;}
    	}
    	while(scanf("%d",&n)==1)
    		printf("%d\n",x[n]);
    	return 0;
    }
    

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    #define maxn 200005
    int d[maxn];
    
    int main()
    {
    	int index1=0,index2=0;
    	int num=1;
    	d[0]=1;
    	while(num<maxn){
    		int b1=d[index1]*2+1;
    		int b2=d[index2]*4+5;
    		if (b1<=b2){
    			d[num++]=b1;
    			index1++;
    		} else d[num++]=b2,index2++;
    	}
    	
    	int n;
    	while(~scanf("%d",&n)){
    		printf("%d\n",d[n-1]);
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    18381
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By