Advertisement
sosiris

get coefficients and odd # occurrence after N steps

Aug 20th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. //in : sieveNum, steps
  2. //out : return value, a, b
  3. uint32_t getCoefficientsAndOddOccurrence(const mp::cpp_int& sieveNum, const uint32_t steps, mp::cpp_int& a, mp::cpp_int& b)
  4. {
  5.   uint32_t odds = 0;
  6.   a = mp::cpp_int(1u) << steps;
  7.   b = sieveNum;
  8.   for (uint32_t i = 0; i < steps; ++i)
  9.   {
  10.     if (static_cast<uint32_t>(b)& 1u)
  11.     {
  12.       a += a >> 1;
  13.       b += (b + 1) >> 1;
  14.       ++odds;
  15.     }
  16.     else
  17.     {
  18.       a >>= 1;
  19.       b >>= 1;
  20.     }
  21.   } //for()
  22.   return odds;
  23. }//getCoefficientsAndOddOccurrence()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement