static void Main(string[] args) { Console.WriteLine("enter number"); int Number; Number = Console.Read(); ConsecutivePrime obj = new ConsecutivePrime(); List <int> numberslist = new List <int>(); for (int i = 0; i <= Number; i++) { if (obj.isPrime(i)) { numbers.Add(i); } } int sum = 2; int count = -1; foreach (int num in numberslist) { sum = sum + num; if (sum < Number && obj.isPrime(sum)) { count++; } } Console.WriteLine(count); }
static void Main(string[] args) { int input_number; int Sum = 2; int Count = 0; Console.WriteLine("enter number:"); input_number = int.Parse(Console.ReadLine()); ConsecutivePrime obj = new ConsecutivePrime(); for (int j = 3; j < input_number; j++) { if (obj.isPrime(j)) { Sum += j; if (obj.isPrime(Sum) && Sum < input_number) { Console.WriteLine(Sum); Count++; } } } Console.WriteLine("total=" + Count); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("enter number"); int number, count = 0, sum, sc = 0; number = Console.Read(); ConsecutivePrime obj = new ConsecutivePrime(); List <int> primelist = new List <int>(); List <int> s = new List <int>(); for (int i = 3; i <= number; ++i) { if (obj.Isprime(i)) { primelist.Add(i); count++; } } /*for(int k=0;k<count;k++) * { * for (int l = 1; l < count - k; ++l) * { * * } * } */ // Console.WriteLine(c); for (int k = 1; k < count; ++k) { for (int l = 1; l < count - k; ++l) { sum = 0; for (int i = l, m = 0; m <= k; ++m, ++i) { sum = sum + primelist[i]; if (sum > number) { break; } } if (obj.Isprime(sum) && sum < number) { sc++; s.Add(sum); } } } Console.WriteLine("\n{0}", s.Count); Console.ReadKey(); }