📜  露丝·亚伦数

📅  最后修改于: 2021-04-22 00:55:43             🧑  作者: Mango

甲数N被认为是露丝-亚伦号码如果N素因数的总和等于N + 1素因数的总和。
Ruth-Aaron的前几个数字是:

检查N是否为Ruth-Aaron数

给定数字N ,任务是查找此数字是否为Ruth-Aaron数。
例子:

方法:我们的想法是找到NN + 1并检查所有适当除数的总和,如果NN + 1适当除数的总和相等或不。如果N和N + 1的适当除数之和相等,则该数字为Ruth-Aaron数。
例如:

下面是上述方法的实现:

C++
// C++ implementation of the above approach
 
#include 
using namespace std;
 
// Function to find prime divisors of
// all numbers from 1 to N
int Sum(int N)
{
    int SumOfPrimeDivisors[N + 1] = { 0 };
 
    for (int i = 2; i <= N; ++i) {
 
        // if the number is prime
        if (!SumOfPrimeDivisors[i]) {
 
            // add this prime to all
            // it's multiples
            for (int j = i; j <= N; j += i) {
 
                SumOfPrimeDivisors[j] += i;
            }
        }
    }
    return SumOfPrimeDivisors[N];
}
 
// Function to check Ruth-Aaron number
bool RuthAaronNumber(int n)
{
    if (Sum(n) == Sum(n + 1))
        return true;
    else
        return false;
}
 
// Driver code
int main()
{
 
    int N = 714;
    if (RuthAaronNumber(N)) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


Java
// Java implementation of the above approach
class GFG{
     
// Function to find prime divisors of
// all numbers from 1 to N
static int Sum(int N)
{
    int SumOfPrimeDivisors[] = new int[N + 1];
 
    for (int i = 2; i <= N; ++i)
    {
 
        // if the number is prime
        if (SumOfPrimeDivisors[i] == 1)
        {
 
            // add this prime to all
            // it's multiples
            for (int j = i; j <= N; j += i)
            {
                SumOfPrimeDivisors[j] += i;
            }
        }
    }
    return SumOfPrimeDivisors[N];
}
 
// Function to check Ruth-Aaron number
static boolean RuthAaronNumber(int n)
{
    if (Sum(n) == Sum(n + 1))
        return true;
    else
        return false;
}
 
// Driver code
public static void main (String[] args)
{
 
    int N = 714;
    if (RuthAaronNumber(N))
    {
        System.out.print("Yes");
    }
    else
    {
        System.out.print("No");
    }
}
}
 
// This code is contributed by Ritik Bansal


Python3
# Python3 implementation of the above approach
 
# Function to find prime divisors of
# all numbers from 1 to N
def Sum(N):
 
    SumOfPrimeDivisors = [0] * (N + 1)
 
    for i in range(2, N + 1):
 
        # If the number is prime
        if (SumOfPrimeDivisors[i] == 0):
 
            # Add this prime to all
            # it's multiples
            for j in range(i, N + 1, i):
                SumOfPrimeDivisors[j] += i
 
    return SumOfPrimeDivisors[N]
 
# Function to check Ruth-Aaron number
def RuthAaronNumber(n):
 
    if (Sum(n) == Sum(n + 1)):
        return True
    else:
        return False
 
# Driver code
N = 714
 
if (RuthAaronNumber(N)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by vishu2908


C#
// C# implementation of the above approach
using System;
class GFG{
     
// Function to find prime divisors of
// all numbers from 1 to N
static int Sum(int N)
{
    int []SumOfPrimeDivisors = new int[N + 1];
 
    for (int i = 2; i <= N; ++i)
    {
 
        // if the number is prime
        if (SumOfPrimeDivisors[i] == 1)
        {
 
            // add this prime to all
            // it's multiples
            for (int j = i; j <= N; j += i)
            {
                SumOfPrimeDivisors[j] += i;
            }
        }
    }
    return SumOfPrimeDivisors[N];
}
 
// Function to check Ruth-Aaron number
static bool RuthAaronNumber(int n)
{
    if (Sum(n) == Sum(n + 1))
        return true;
    else
        return false;
}
 
// Driver code
public static void Main()
{
    int N = 714;
    if (RuthAaronNumber(N))
    {
        Console.Write("Yes");
    }
    else
    {
        Console.Write("No");
    }
}
}
 
// This code is contributed by Code_Mech


Javascript


输出:
Yes

参考: https : //oeis.org/A006145