How to print the first abundant odd number greater than one billion in C#

1 Answer

0 votes
using System;

// abundant odd number = sum of proper divisors > number

public class MyClass {
	private static int SumOddNumberProperDivisors(int num) {
		int sum = 1;

		for (int i = 3, j; i < Math.Sqrt(num) + 1; i += 2) {
			if (num % i == 0) {
				sum += i + (i == (j = num / i) ? 0 : j);
			}
		}

		return sum;
	}
	public static void Main(string[] args)
	{
		int num = 1000000001; 
		
		for (;; num += 2) {
			if (SumOddNumberProperDivisors(num) > num) {
				break;
			}
		}

		Console.Write(num);
	}
}






/*
run:
   
1000000575
   
*/

 



answered Oct 31, 2022 by avibootz

Related questions

...