Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int st[100], vf,st2[100],r=-1,i;
- int nr,b;
- void Init(int k)
- {
- st[k] = 0;
- }
- int Succesor(int k) {
- if (st[k] < nr)
- {
- st[k]++;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int Valid(k) {
- for (i = 1; i < k; i++)
- {
- if (st[i] == st[k])
- return 0;
- }
- return 1;
- }
- int Solution(int k)
- {
- return (k == nr);
- }
- int prim(int k)
- {
- int d, ok = 1;
- for (d = 2; d <= k / 2; d++)
- {
- if (k%d == 0)
- ok = 0;
- }
- return ok;
- }
- void Back() {
- int isS, isV, x, aux, a[10], co, p = 1, co1 = 1;
- for (x = 2; x < b; x++)
- {
- nr = 0;
- a[1] = 0;
- a[2] = 0;
- a[3] = 0;
- a[4] = 0;
- a[5] = 0;
- a[6] = 0;
- aux = x;
- co = x;
- while (aux > 0)
- {
- nr++;
- a[nr] = aux % 10;
- aux = aux / 10;
- }
- vf = 1;
- Init(vf);
- while (vf > 0)
- {
- isS = 0;
- isV = 0;
- if (vf <= nr)
- {
- do {
- isS = Succesor(vf);
- if (isS)
- {
- isV = Valid(vf);
- }
- } while (isS && !isV);
- }
- if (isS)
- {
- if (Solution(vf))
- {
- if (co == co1)
- {
- aux = 0;
- if (p == 1) {
- for (i = 1; i <= nr; i++)
- aux = aux * 10 + a[st[i]];
- p = prim(aux);
- }
- }
- else
- {
- if (p == 1 && co1 != 1)
- {
- r++;
- st2[r] = co1;
- }
- co1 = co;
- p = 1;
- aux = 0;
- for (i = 1; i <= nr; i++)
- aux = aux * 10 + a[st[i]];
- p = prim(aux);
- }
- }
- else
- {
- vf++;
- Init(vf);
- }
- }
- else
- {
- vf--;
- }
- }
- }
- }
- void main()
- {
- FILE *intrare = fopen("in.txt", "rt");
- FILE *iesire = fopen("out.txt", "wt");
- fscanf(intrare, "%d", &b);
- Back();
- for(i=0;i<=r;i++)
- fprintf(iesire, "%d\n", st2[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement