Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("numere23.in");
- ofstream fout("numere23.out");
- int prim3(int n)
- {
- if(n == 1)
- return 0;
- int e, cnt = 0;
- for(int d = 2;d <= n;d++)
- {
- e = 0;
- while(n % d == 0)
- {
- e++;
- n /= d;
- }
- if(e > 0)
- cnt++;
- }
- if(cnt <= 3)
- return 1;
- else
- return 0;
- }
- int main()
- {
- int n, k, c, pr3[10100], j = 2, i = 0, maxim = -1, q, cnt = 2, poz = 1, sol[10100], f[10100], rest;
- fin >> n >> k >> c;
- if(c == 1)
- {
- while(i <= n)
- {
- if(prim3(j) == 1)
- pr3[++i] = j;
- j++;
- }
- for(q = 1;q <= n;q++)
- maxim = max(pr3[q], maxim);
- fout << maxim;
- }
- else if(c == 2)
- {
- while(i <= n)
- {
- if(prim3(j) == 1)
- pr3[++i] = j;
- j++;
- }
- q = 1;
- poz = 1;
- sol[1] = pr3[1];
- f[pr3[1]]++;
- rest = 0;
- while(cnt <= n)
- {
- poz += k;
- if(poz > n)
- poz = poz % n;
- if(sol[poz] == 0)
- {
- sol[poz] = pr3[++q];
- cnt++;
- }
- else
- {
- while(sol[poz] != 0)
- {
- poz++;
- if(poz > n)
- poz = poz % n;
- }
- }
- for(i = poz;i <= n;i++)
- {
- if(sol[i] != 0)
- poz++;
- if(poz > n)
- poz = poz % n;
- }
- }
- for(q = 1;q <= n;q++)
- fout << sol[q] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement