Computer Programming Contest Preparation

ToolBox - Source for: 3/305/x.cpp



/home/toolbox/public_html/solutions/3/305/x.cpp
    1 #include <cstdio>
    2 using namespace std;
    3 
    4 int main()
    5 {
    6     int k;
    7     int ans[13] = { 2, 7, 5, 30, 169, 441, 1872, 7632, 1740, 93313, 459901,
    8                     1358657, 2504881
    9                   };
   10 
   11     while (scanf("%d", &k), k)
   12         {
   13             printf("%d\n",ans[k-1]);
   14 
   15             long m;
   16             for (m = k + 1; m < 2000000000; m++)
   17                 {
   18                     int pos = 0;
   19                     bool found = true;
   20                     for (int i = 0; i < k; i++)
   21                         {
   22                             pos = (pos + m - 1) % ((2 * k) - i);
   23                             if (pos < k)
   24                                 {
   25                                     found = false;
   26                                     break;
   27                                 }
   28                         }
   29                     if (found)
   30                         break;
   31                 }
   32             // printf("%ld\n", m);
   33         }
   34 
   35     return 0;
   36 }
   37