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 nr;
- 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) {
- int i;
- for (i = 1; i < k; i++)
- {
- if (st[i] == st[k])
- return 0;
- }
- return 1;
- }
- int Solution(int k)
- {
- return (k == nr);
- }
- void Print() {
- int i;
- for (i = 1; i <= nr; i++)
- {
- printf("%d ", st[i]);
- }
- printf("\n");
- }
- 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],i,co,p=1,co1=1;
- for (x = 2; x < 10000; 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)
- printf("%d\n", 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()
- {
- printf("Toate numerele prime circulare pana in 10.000 sunt:\n");
- Back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement