Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = new int[10];
- Work ob = new Work();
- ob.Go(arr);
- Console.ReadLine();
- }
- }
- class Work
- {
- public void Go(int[] arr)
- {
- int temp = 2;
- for(int i = 0; i < arr.Length; i++)
- {
- if (i == 0) { arr[i] = temp; continue; }
- if (i == 1) { arr[i] = (temp = temp + 1); temp++; continue; }
- if ((1 == (temp / temp)) && ((temp / 1) == temp))
- { //это проверка на "простое ли число" (ошибочна) не хватает условия "которое не делится без остатка ни на одно другое целое положительное число"
- // поэтому всё решение и разваливается. Собственно, как это реализовать???
- arr[i] = temp; temp++; }
- }
- for(int j = 0; j < arr.Length; j++)
- {
- Console.WriteLine(arr[j]);
- }
- }
- }
- bool IsPrime(int x)
- {
- if (x % 2 == 0)
- return x == 2;
- for (int q=3; q*q<=x; q+=2)
- if (x % q == 0)
- return false;
- return true;
- }
- private static readonly List<int> Primes = new List<int> { 2, 3 };
- private static void AddNextPrime(int x)
- {
- foreach (int i in Primes)
- {
- if ((x % i) == 0)
- return;
- if (i * i > x)
- break;
- }
- Primes.Add(x);
- }
- int i = Primes.Last() + 2;
- while (Primes.Count < 10)
- {
- AddNextPrime(i++);
- }
- class Work
- {
- static void Go(int[] a)
- {
- int value = 1;
- for (int i = 0; i < a.Length; i++)
- {
- bool prime = true;
- do
- {
- ++value;
- for (int j = 0; j < i && a[i] <= value / 2 && (prime = value % a[j] != 0); ++j) ;
- } while (!prime);
- a[i] = value;
- }
- }
- }
- Work.Go( arr );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement