Advertisement
Guest User

Untitled

a guest
Mar 9th, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 60
  3. #define M 158
  4.  
  5. inline int gcd(int a, int b) {
  6.     while(a&&b) {
  7.         if (a>b) a%=b;
  8.         else b%=a;
  9.     }
  10.     return a+b;
  11. }
  12.  
  13. int r[M] = {6, 10, 12, 14, 15, 18, 20, 21, 22, 24, 26, 28, 30, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46, 48, 50, 51, 52, 54, 55, 56, 57, 58, 60, 62, 63, 65, 66, 68, 69, 70, 72, 74, 75, 76, 77, 78, 80, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 98, 99, 100, 102, 104, 105, 106, 108, 110, 111, 112, 114, 115, 116, 117, 118, 119, 120, 122, 123, 124, 126, 129, 130, 132, 133, 134, 135, 136, 138, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 164, 165, 166, 168, 170, 171, 172, 174, 175, 176, 177, 178, 180, 182, 183, 184, 185, 186, 187, 188, 189, 190, 192, 194, 195, 196, 198, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 218, 219, 220};
  14. int g[M][M];
  15. int n=3,p=0;
  16. int st[N];
  17. int tg = 0;
  18.  
  19. void rec(int l) {
  20.     int i,j,k,otg=tg;
  21.     if (p==n) {
  22.         if (tg>1) return;
  23.         printf("%d:",n);
  24.         for (i=0;i<n;i++) printf(" %d%c",r[st[i]],",\n"[i==n-1]);
  25.         n++;
  26.     }
  27.     for (i=n-p-1;i<l;i++) {
  28.         for (j=0;j<p;j++) if (g[st[j]][i]<2) break;
  29.         if (j>=p) {
  30.             st[p++]=i;
  31.             if (otg) tg = gcd(otg,r[i]);
  32.             else tg = r[i];
  33.             rec(i);
  34.             p--;
  35.         }
  36.     }
  37.     tg = otg;
  38. }
  39.  
  40. int main () {
  41.     int i,j;
  42.     for (i=0;i<M;i++)
  43.         for (j=0;j<M;j++)
  44.             g[i][j]=gcd(r[i],r[j]);
  45.     rec(M);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement