1 条题解

  • 0
    @ 2025-10-10 15:48:08

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
    	int n;
    	cin>>n;
    	string s1,s2,s3 = "";
    	s1 = "4567";
    	s2 = "123";
    	while(s3.size() < n){
    		s3 = s2 + s1;
    		s1 = s2;
    		s2 = s3;
    	}
    	
    	cout<<s3[n - 1]<<endl;
    }
    
    
    

    Pascal :

    program chaojizifuchuan;
    var
      n,tochange,tcd:longint;
    
    function need(t1:longint):longint;
    var
      sum,xh,sum2,su:longint;
    begin
      xh:=2;             
      sum:=7;           
      sum2:=10;          
      while sum2<t1 do       
      begin
        inc(xh);                
        su:=sum2;               
        sum2:=sum+sum2;        
        sum:=su;                
      end;
      if t1<=7 then xh:=1;   
      tochange:=sum2;    
      tcd:=sum;             
      exit(xh);            
    end;
    
    procedure printf(t2:char);
    begin
      writeln(t2);       
      halt;              
    end;
    
    procedure try(len:longint);
    var
      bu,total,last:longint;
      c:string;
    begin
      if len<=7 then begin              
                             c:='1234567';
                             printf(c[len]);
                         end
      else begin                             
                bu:=need(len);                
                total:=tochange;               
                tochange:=0;                    
                if odd(bu) then last:=4
                      else last:=3; 
                if len>=total-last then begin 
                                                    if last=4 then c:='4567'
                                                       else c:='123'; 
                                                    printf(c[len-total+last]); 
                                                end
                else begin
                         dec(bu);
                         total:=tcd; 
                         tcd:=0; 
                         try(len-total);
                       end;
            end;
    
    end;
    begin
        readln(n);            
        try(n);                   
    end.
    
    • 1

    信息

    ID
    459
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者