Advertisement
bartekltg

marynarz 2

Jan 13th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. // gra_marynarz.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <algorithm>
  7.  
  8.  
  9.   int *trafien;
  10.   int *ntrafien;
  11.   int *cumsum;
  12.  
  13. void graj3 (int graczy, int palcow, int modulo)
  14. {
  15.  
  16.  
  17.     trafien[0]=1;
  18.     for (int i=1;i<graczy;i++)
  19.         trafien[i]=0;
  20.  
  21.     for (int gr=0;gr<graczy;gr++)
  22.     {
  23.        
  24.         for (int g=0;g<graczy;g++) 
  25.         {
  26.             ntrafien[g] = 0;
  27.         }
  28.         cumsum[0]=trafien[0];
  29.         for (int g=1;g<graczy+palcow+1;g++)
  30.         {
  31.             cumsum[g] = cumsum[g-1]+trafien[g % graczy];
  32.         }
  33.  
  34.  
  35.         for (int g=0;g<graczy;g++)
  36.         {
  37.             ntrafien[g] = (cumsum[g+palcow] - cumsum[g])%modulo;
  38.         }
  39.         std::swap(trafien,ntrafien);
  40.     }
  41.  
  42.     //printf ("\n graczy %d palcow %d\n",graczy,palcow);
  43.     //for (int gr=0;gr<graczy;gr++)
  44.     //{
  45.     //  printf("%lld\n ",trafien[gr]);
  46.     //}
  47.  
  48.       int suma=0;
  49.     for (int gr=1;gr<graczy;gr++)
  50.     {
  51.         if (trafien[gr-1]!=trafien[gr]) suma=1;
  52.     }
  53.     if (suma==0)printf ("%d %d\n" ,graczy,palcow);
  54.  
  55. }
  56.  
  57. int modpower(int x,int n, int m )
  58. {// x^n mod m
  59.     if (n==0) return 1;
  60.     if (n%2==1) return (x*modpower(x,n-1,m))%m;
  61.     else
  62.     {
  63.         int a = modpower(x,n/2,m);
  64.         return (a*a)%m;
  65.     }
  66. }
  67.  
  68.  
  69. int main()
  70. {
  71.     const int max_graczy=2000;
  72.     const int max_palcow=2000;
  73.        
  74.     trafien = new    int[max_graczy];
  75.     ntrafien = new    int[max_graczy];
  76.     cumsum = new   int[max_graczy+max_palcow+1];
  77.  
  78.     int procent=0;
  79.     for (int graczy = 2;graczy<max_graczy;graczy++)
  80.     {
  81.         if (procent*max_graczy<=graczy*1000) { printf("%.2lf%%.\n",((double)procent++/10));};
  82.        
  83.         for (int palcow = 2;palcow<max_palcow;palcow++)
  84.             if ((modpower(palcow,graczy,graczy)==0) && (palcow%graczy!=0)) 
  85.                 // czy p^g / g = naturalna <=> p^g =  0 (mod g) oraz czy nie trywialne
  86.                 graj3(graczy,palcow, 9973); //9973 to jakaś liczba pierwsza
  87.     }
  88.        
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement