1 条题解

  • 0
    @ 2025-4-27 18:52:07

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    bool dizeng(int n){
    	int a[10] = {0};
    	
    	if(n < 1000 && n / 100 != 1){
    		return false;
    	} 
    	int k = 0; 
    	bool f = true;
    	while(n != 0){
    		a[k] = n % 10;
    		if(k != 0 && a[k] - a[k-1] != -1){
    			f = false;
    			break;
    		}
    		k++;
    		n = n / 10;
    	}
    	
    	return f;
    }
    
    int he(int n){
    	int s = 0;
    	while(n != 0){
    		s = s + n % 10;
    		n = n / 10;
    	}
    	return s;
    }
    
    int main(){
    	int i,j,n,c = 0;
    	//前4位 
    	for(i = 123;i <= 6789;i++){
    		for(j = 123;j <= 6789;j++){
    			if(dizeng(i) && dizeng(j) && sqrt(he(i) + he(j)) == (int)sqrt(he(i) + he(j))){
    //				if(i < 1000) cout<<0;
    //				cout<<i;
    //				if(j < 1000) cout<<0;
    //				cout<<j<<" "<<he(i)+he(j)<<" "<<sqrt(he(i)+he(j))<<endl;
    				c++;
    			}
    		}
    	}
    	
    	cout<<c;
    }
    
    
    

    Pascal :

    var 
     a,b:integer;
     s,t,ct:integer;
    begin
       ct:=0;
       for a:=0 to 6 do
       begin
          for b:=0 to 6 do
          begin
            s:=4*a+4*b+12; 
            t:=trunc(sqrt(double(s)));
            if s=t*t then    
              inc(ct);         
          end;
       end;
       writeln(ct); 
    end.
    
    • 1

    信息

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