hi , i need to solve this question but im stuck at getting the factors , but what i need to do is...
A positive number n is consecutive-factored if and only if it has factors, i and j where i > 1, j > 1 and j = i + 1. Write a function named isConsecutiveFactored that returns 1 if its argument is consecutive-factored, otherwise it returns 0. the function signature is int isConsectiveFactored(int n)
the function signature is int isConsectiveFactored(int n) Example
If n is 24 return 1 because 24 = 2*3*4 and 3 = 2 + 1
If n is 105 return 0 because 105 = 3*5*7 and 5 != 3+1 and 7 != 5+1
If n is 90 return 1 because factors of 90 include 2 and 3 and 3 = 2 + 1
so far ive been able to get the factor i.e if the number is 24 then ive been able to get 2 and 12 , but im stuck there and blanked....
using System;
using System.Collections.Generic;
using System.Text;
namespace isConsecutiveFactored
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(isConsecutiveFactored(24));
}
private static int isConsecutiveFactored(int p)
{
foreach (int a1 in getFactor(24))
{
Console.WriteLine(a1);
}
return 0;
}
private static List<int> getFactor(int p)
{
List<int> factor = new List<int>();
int max = (int)Math.Sqrt(p);
for (int i = 1; i <= max; i++)
{
if (i != 0)
{
if ((p % i) == 0)
{
if (i != max)
{
if ((p / i) != 1 && (p / i) != p)
{
factor.Add(i);
factor.Add(p / i);
//Console.WriteLine((p / i) + " " + "this is the factor");
}
}
}
}
//
}
List<int> fac = factor.GetRange(0, 2);
return fac;
}
}
}
can anybody help me with this .....