1 条题解

  • 0
    @ 2023-1-9 9:34:38

    1

    #include <bits/stdc++.h>
    using namespace std;
    // 返回 x 的因子和
    int f(int x)
    {
        if (x <= 1)
            return 0;
        int res = 1;
        for (int i = 2; i <= x - 1; i++)
            if (x % i == 0)
                res += i;
        return res;
    }
    int main()
    {
        for (int a = 1;; a++)
        {
            int b = f(a);
            if (a == f(b) && a != b)
            {
                cout << a << " " << b << "\n";
                break;
            }
        }
        return 0;
    }
    

    2

    #include <bits/stdc++.h>
    using namespace std;
    //返回 x 的因子和
    int f(int x)
    {
        if (x <= 1)
            return 0;
        int res = 1;
        for (int i = 2; i * i <= x; i++)
            if (x % i == 0)
            {
                int j = x / i; //找到对应的另一个因子
                res += i;
                if (j != i)
                    res += j;
            }
        return res;
    }
    int main()
    {
        for (int a = 1;; a++)
        {
            int b = f(a);
            if (a == f(b) && a != b)
            {
                cout << a << " " << b << "\n";
                break;
            }
        }
        return 0;
    }
    
    • 1

    信息

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