Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //1,2,3,5,7,9
- Console.WriteLine(Suma3(-1, 8));
- //Console.WriteLine(ilePierwszychwPrzedziale(6, 8));
- //Console.WriteLine(ilePierwszychwPrzedziale(1, 5));
- Console.ReadKey();
- }
- static uint Suma3(int a, int b)
- {
- uint wynik = 0;
- for (int i = a; i <= b; i++)
- {
- if (i == 1)
- {
- wynik++;
- }
- if (pierwszaCiapki(i) == true)
- {
- wynik++;
- }
- }
- return wynik;
- }
- static bool pierwszaCiapki(int n)
- {
- if (n < 2)
- {
- return false;
- }
- for (int i = 2; i <= (n / 2); i++)
- {
- if (n % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement