Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //1,2,3,5,7,9
  14. Console.WriteLine(Suma3(-1, 8));
  15. //Console.WriteLine(ilePierwszychwPrzedziale(6, 8));
  16. //Console.WriteLine(ilePierwszychwPrzedziale(1, 5));
  17. Console.ReadKey();
  18. }
  19.  
  20. static uint Suma3(int a, int b)
  21. {
  22. uint wynik = 0;
  23.  
  24. for (int i = a; i <= b; i++)
  25. {
  26. if (i == 1)
  27. {
  28. wynik++;
  29. }
  30. if (pierwszaCiapki(i) == true)
  31. {
  32. wynik++;
  33. }
  34. }
  35.  
  36. return wynik;
  37. }
  38.  
  39. static bool pierwszaCiapki(int n)
  40. {
  41. if (n < 2)
  42. {
  43. return false;
  44. }
  45. for (int i = 2; i <= (n / 2); i++)
  46. {
  47. if (n % i == 0)
  48. {
  49. return false;
  50. }
  51. }
  52. return true;
  53. }
  54.  
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement