Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. int[] arr = new int[10];
  6. Work ob = new Work();
  7. ob.Go(arr);
  8.  
  9. Console.ReadLine();
  10. }
  11. }
  12. class Work
  13. {
  14. public void Go(int[] arr)
  15. {
  16. int temp = 2;
  17. for(int i = 0; i < arr.Length; i++)
  18. {
  19. if (i == 0) { arr[i] = temp; continue; }
  20. if (i == 1) { arr[i] = (temp = temp + 1); temp++; continue; }
  21. if ((1 == (temp / temp)) && ((temp / 1) == temp))
  22. { //это проверка на "простое ли число" (ошибочна) не хватает условия "которое не делится без остатка ни на одно другое целое положительное число"
  23. // поэтому всё решение и разваливается. Собственно, как это реализовать???
  24. arr[i] = temp; temp++; }
  25. }
  26. for(int j = 0; j < arr.Length; j++)
  27. {
  28. Console.WriteLine(arr[j]);
  29. }
  30. }
  31. }
  32.  
  33. bool IsPrime(int x)
  34. {
  35. if (x % 2 == 0)
  36. return x == 2;
  37.  
  38. for (int q=3; q*q<=x; q+=2)
  39. if (x % q == 0)
  40. return false;
  41.  
  42. return true;
  43. }
  44.  
  45. private static readonly List<int> Primes = new List<int> { 2, 3 };
  46.  
  47. private static void AddNextPrime(int x)
  48. {
  49. foreach (int i in Primes)
  50. {
  51. if ((x % i) == 0)
  52. return;
  53. if (i * i > x)
  54. break;
  55. }
  56. Primes.Add(x);
  57. }
  58.  
  59. int i = Primes.Last() + 2;
  60. while (Primes.Count < 10)
  61. {
  62. AddNextPrime(i++);
  63. }
  64.  
  65. class Work
  66. {
  67. static void Go(int[] a)
  68. {
  69. int value = 1;
  70.  
  71. for (int i = 0; i < a.Length; i++)
  72. {
  73. bool prime = true;
  74. do
  75. {
  76. ++value;
  77. for (int j = 0; j < i && a[i] <= value / 2 && (prime = value % a[j] != 0); ++j) ;
  78. } while (!prime);
  79.  
  80. a[i] = value;
  81. }
  82. }
  83. }
  84.  
  85. Work.Go( arr );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement