The task is the following: the user is given a sequence of numbers from 1 to n, we check whether the product of two numbers from the sequence can be equal to the sum of all numbers of the sequence, not counting these 2 numbers. For example: a series from 1 to n, where n = 26. The product of the numbers 15 and 21 is equal to the sum of all the numbers except 21 and 15. Here is the code:
using System.Collections.Generic; public class RemovedNumbers { public static int Sum(long n) { int sum=0; for(int i =1;i<=n;i++) { sum+=i; } return sum; } public static List<int[]> removNb(long n) { int sum=Sum(n); List <int[]> list = new List<int []>(); int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i*j == sum-(i+j)) { list.Add(new int [] {i,j}); list.Add(new int [] {j,i}); return list; } } } return list; } } The code runs in 0.015 seconds, you need to optimize to 0.008, what do you advise?