Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int st[100], vf;
- int N, Q, V;
- int nr=0;
- int patrat_perfect(int x)
- {
- int d;
- for (d = 2; d <= x / 2; d++)
- {
- if (d*d == x)
- return 1;
- }
- return 0;
- }
- void Init(int k)
- {
- st[k] = 0;
- }
- int Succesor(int k) {
- if (patrat_perfect(st[k]) == 1)
- nr--;
- if (st[k] < V)
- {
- st[k]++;
- {
- if (patrat_perfect(st[k]) == 1)
- nr++;
- }
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int Solution(int k)
- {
- if (k == N)
- return 1;
- else
- return 0;
- }
- void Print() {
- FILE *fis_out = fopen("out.txt", "wt");
- int i;
- for (i = 1; i <= N; i++)
- {
- fprintf(fis_out,"%d ", st[i]);
- }
- printf("\n");
- }
- void Back()
- {
- int iS, iV, i, j, k, suma, poz;
- vf = 1;
- Init(vf);
- while (vf > 0)
- {
- iS = 0;
- iV = 0;
- do {
- iS = Succesor(vf);
- if (iS)
- {
- iV = 1;
- }
- } while (iS && !iV);
- if (iS)
- {
- if (Solution(vf))
- {
- if (nr == Q)
- {
- Print(vf);
- }
- }
- else
- {
- vf++;
- Init(vf);
- }
- }
- else
- {
- vf--;
- }
- }
- }
- void main()
- {
- FILE *fis = fopen("in.txt", "rt");
- fscanf(fis,"%d", &N);
- fscanf(fis,"%d", &Q);
- fscanf(fis,"%d", &V);
- Back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement