aryobarzan

Euler 78

Jun 11th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int p[2][(int)1e6+10];
  6.  
  7. const int mod=1e6;
  8. const int MAX=1e5;
  9.  
  10. //p[k][n]= p[k-1][n]+p[k][n-k]
  11.  
  12. int main()
  13. {
  14.     p[0][0]=p[1][0]=1;
  15.     for(int k=1;k<=MAX;++k)
  16.     {
  17.         if(k%(MAX/100)==0)
  18.             cerr<<"R:"<<k/(MAX/100)<<"%"<<endl;
  19.         for(int i=0;i<k;++i)
  20.             p[k%2][i]=p[(k-1)%2][i];
  21.         for(int n=k;n<=MAX;++n)
  22.         {
  23.             p[k%2][n]=p[(k-1)%2][n]+p[k%2][n-k];
  24.             p[k%2][n]%=mod;
  25.             if(n==k and p[k%2][n]==0)
  26.             {
  27.                 cout<<n<<"::"<<p[k%2][n]<<endl;
  28.                 return 0;
  29.             }
  30.         }
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment