Exclusive square number~

As the title:

Xiao Ming was staring at the number 203879 in a daze.
It turns out, 203879 * 203879 = 41566646641
What is the magic of this? Observe carefully, 203879 is a 6-digit number, and the number on each digit of it is different, and there are no digits that make up itself on all the digits after its square.
There is another 6-digit number with such characteristics, please find it out!
Summarize the filtering requirements:
1. 6-digit positive integer
2. The number on each digit is different
3. Each digit of its square number does not contain the original number. The

answer is a 6-digit positive integer.

Directly on the code:

#include <stdio.h>

int main()

{
    
    

    long long i,j,k,m,n;
    
    int x=1,y=1;//备用
    
    long long a[6];//这是给那几个每个数位都是不同的数准备的 
    
    long long b[12];//这是给那些数的平方准备的,六位数平方最大也不超过十二位 
    
    for(i = 100000; i < 999999; i++){
    
    
    
        j = i;
        
        for(n=0;j>0;n++)
        {
    
    
        
        	k = j%10;
        	
        	a[n] = k;//把i的每一位都放到a[]中去 
        	
        	j = j/10;
        	
		}
        if(a[0]!=a[1]&&a[0]!=a[2]&&a[0]!=a[3]&&a[0]!=a[4]&&a[0]!=a[5] && a[1]!=a[2]&&a[1]!=a[3]&&a[1]!=a[4]&&a[1]!=a[5]
            && a[2]!=a[3]&&a[2]!=a[4]&&a[2]!=a[5] && a[3]!=a[4]&&a[3]!=a[5] && a[4]!=a[5])
            
			//上面是笨方法,本来我认为用了个自以为很方便的方法,然后做完了之后,找bug找了一个多小时,没找出来。用了笨方法就行了。。(实际是我菜) 
			{
    
    
                j = i*i;
                
                k = j%10;
                
                n = 0;
                
                while(j > 0){
    
    
                
                    b[n] = k;//把b存进去
                    
                    j = j/10;
                    
                    k = j%10;
                    
                    n++;
                }
                
                for(n = 0; n <= 5; n++){
    
    
                
                    for(m = 0; m <= 11; m++){
    
    //比较a和b是否有重合
                    
                        if(a[n] == b[m]) goto loop;
                    }
                    
                    loop:if(n!=6 && m!=12)break;
                    
                }
                if(n == 6 && m == 12&&i!=203879)
                
				{
    
    
					printf("%lld\n",i);//没有的话就输出
				}
            }
    }
}

Here is the running diagram:
Insert picture description here
Ah. It took about 50 minutes to do the question, but no results were produced. I slowly corrected the mistakes. It took more than an hour to debug!

xdm! Write code carefully in the future!

Guess you like

Origin blog.csdn.net/FG_future/article/details/112411258