Wednesday, February 29, 2012

My solution of UVA 305 Joseph Solution


#include <iostream>
#include <sstream>


#include <algorithm>
#include <vector>
#include <list>


#define sz(k) (int)(k).size()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define forr(i,r) for(int i=0;i<r;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back


#define nl(c) c<<endl;
#define db(cout,c) tr(c,it){cout<<" "<<*it;};nl(cout); 
#define INF (int)(1<<31-1)


using namespace std;
int res[]={0,
2,
7,
5,
30,
169,
441,
1872,
7632,
1740,
93313,
459901,
1358657,
2504881,
13482720
};


int main(int argc, char *argv[])
{
    int K;
    while(cin>>K)
    {
        if(K==0)break;
        cout<<res[K]<<endl;
/*        
        int KK=2*K;


//cout<<"K="<<K<<endl;
        // P[0]=(M-1)%2K
        // P[i+1] = (P[i]+M-1) % (2K-i)
        // we need solve M where P[0] to P[K-1] >= K


        for(int M=K+1;M<INF;M++)
        {
//cout<<"  M="<<M<<endl<<"    ";
           bool test=true;
           int p=0;
//cout<<p<<"-";
           rep(i,0,K-1)
           {    p=(p+M-1)%(KK-i);
//cout<<p<<"-";
                if(p<K)
                {   test=false;
                    break;
                }
           }
           if(test)
           { 
                cout<<M<<endl;
                break;
           }
//cout<<endl;
        }
*/        
    }
    
//    system("PAUSE");
    return 0;
}

No comments:

Post a Comment