1 条题解

  • 0
    @ 2023-6-11 12:22:23

    C :

    #include <stdio.h>
    int ax[10000];
    int ay[10000];
    int main()
    {
        int x,y;
        scanf("%d %d",&x,&y);
        int i;
        int jx=0,jy=0;
        int sumx=0,sumy=0;
        //分别求x和y的所有约数
        for(i=1; i<=x/2; i++)
        {
            if(x%i==0)
            {
                ax[jx]=i;
                jx++;
            }
        }
        for(i=1; i<=y/2; i++)
        {
            if(y%i==0)
            {
                ay[jy]=i;
                jy++;
            }
        }
        //求两个数的约数和
        for(i=0; i<jx; i++)
            sumx+=ax[i];
        for(i=0; i<jy; i++)
            sumy+=ay[i];
        if(sumx==y&&sumy==x)
            printf("yes\n");
        else
            printf("no\n");
        return 0;
    }
    

    C++ :

    #include<iostream>
    #include<cmath>
    using namespace std;
    long long a,b,gsa=0,gsb=0;
    int main()
    {
    	cin>>a>>b;
    	for(int i=1; i<a; i++)
    	{
    		if(a%i==0) gsa+=i;
    	} 
    	for(int i=1; i<b; i++)
    	{
    		if(b%i==0) gsb+=i;
    	}
    	if(gsa==b && gsb==a) cout<<"yes";
    	else cout<<"no";
    	return 0;
    } 
    

    Java :

    
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int s1 = 0,s2 = 0;
            for(int i = 1;i < a;i++){
                if(a % i == 0)s1 = s1 + i;
            }
            for(int i = 1;i < b;i++){
                if(b % i == 0)s2 = s2 + i;
            }
            if(s1 == b || s2 == a) System.out.println("yes");
            else System.out.println("no");
    
    
        }public static void paiXu(int[] a,int length){
            int temp;
            for(int i = 0;i < length - 1;i++){
                for(int k = 0;k < length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        } public static void paiXud(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] < a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        } public static void paiXux(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
    
        public static int MAX(int[] a){
            int max = a[0];
            for (int i = 0; i < a.length; i++) {
                if(max < a[i]){
                    max = a[i];
                }
            }
            return max;
        }
    
        public static int MIN(int[] a){
            int min = a[0];
            for (int i = 0; i < a.length; i++) {
                if(min > a[i]){
                   min = a[i];
                }
            }
            return min;
        }
        public static int sum(int a){
            int x,s = 0;
            while(a != 0){
                x = a % 10;
                s = s + x;
                a /= 10;
            }
            return s;
        }
        public static boolean isPrime(int a){
            if(a <= 1)return false;
            else
            for(int i = 2;i <= Math.sqrt(a);i++){
                if(a % i == 0)return false;
            }return true;
        }
    
        public static long qiuYu(long i){
            long a;
            a = i % 10;
            return a;
        }
        public static int daoXu(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s * 10 + x;
                x /= 10;
            }
            return s;
        }
    
        public static int jiaWei(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s + m;
                x /= 10;
            }
            return s;
        }
    
    }
    

    Python :

    def qh(n):
        s=0
        for i in range(1,n//2+1):
            if(n%i==0):
                s=s+i
        return(s)
    sr=input().split()
    n1=int(sr[0])
    n2=int(sr[1])
    s1=qh(n1)
    s2=qh(n2)
    if(s1==n2 and s2==n1):
        print("yes")
    else:
        print("no")
    
    • 1

    信息

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