Advertisement
sm2345

Untitled

Jan 15th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Code:
  2. #include<iostream>
  3. #include<stdio.h>
  4. using namespace std;
  5. int power(int n, int i)
  6. {
  7.     if(i==0) return 1;
  8.     else return n*power(n,i-1);
  9. }
  10.  
  11. void assigndectohex(int*a, int n)
  12. {
  13.     for(int i=7;i>=0;i--)
  14.     {
  15.         a[i]=n%6;
  16.         n=n/6;
  17.     }
  18. }
  19.  
  20. int hextodec(int*a)
  21. {
  22.     int n=0;
  23.     for(int i=0;i<8;i++)
  24.         n=n+a[i]*power(6,i);
  25.     return n;
  26. }
  27.  
  28. int main()
  29. {
  30.     FILE*fp=fopen("omo39out.txt","w");
  31.     int a[8][8], flag,count;
  32.     for(int n=1;n<=1679615;n++)
  33.     {
  34.         flag=1;
  35.         assigndectohex(a[0],n);
  36.         for(int i=1;i<8;i++)
  37.         {
  38.             for(int j=0;j<8;j++)
  39.             {
  40.                 a[i][(j+7)%8]=a[i-1][j];
  41.             }
  42.         }
  43.        
  44.         for(int i=1;i<8;i++)
  45.         {
  46.             if((hextodec(a[i])%hextodec(a[0]))!=0)
  47.             {
  48.                 flag=0; break;
  49.             }
  50.         }
  51.        
  52.         if(flag==1)
  53.         {
  54.             count++;
  55.             for(int i=0;i<8;i++)
  56.             {fprintf(fp,"%d", a[0][i]);}
  57.             fprintf(fp,"\n");
  58.         }
  59.     }
  60.     fclose(fp);
  61.     printf("So count of such numbers=%d",count);
  62.     return 0;
  63. }
  64. //Output:
  65. 10000000
  66. 10001000
  67. 10100000
  68. 10101010
  69. 11000000
  70. 11001100
  71. 11110000
  72. 11111111
  73. 20000000
  74. 20002000
  75. 20200000
  76. 20202020
  77. 22000000
  78. 22002200
  79. 22220000
  80. 22222222
  81. 30000000
  82. 30003000
  83. 30300000
  84. 30303030
  85. 33000000
  86. 33003300
  87. 33330000
  88. 33333333
  89. 40000000
  90. 40004000
  91. 40400000
  92. 40404040
  93. 44000000
  94. 44004400
  95. 44440000
  96. 44444444
  97. 50000000
  98. 50005000
  99. 50500000
  100. 50505050
  101. 55000000
  102. 55005500
  103. 55550000
  104. 46
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement