Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <random>
  2. #include <vector>
  3. #include <bitset>
  4. #include <iostream>
  5.  
  6. #define N 80000000
  7.  
  8. typedef unsigned long long u64;
  9. typedef unsigned char u8;
  10.  
  11. static u8 cut_row(u64 tile, u8 i) { return (tile >> (8u * i)) & 0xff; }
  12.  
  13. static u8 cut_col(u64 tile, u8 col) {
  14.   u8 ans = 0;
  15.   for (u8 i = 0; i < 8; i++)
  16.     if (tile & (1ull << (8 * i + col)))
  17.       ans |= 1u << i;
  18.   return ans;
  19. }
  20.  
  21. u64 mul(u64 a, u64 b) {
  22.   u64 ans = 0;
  23.   for (u8 i = 0; i < 8; i++)
  24.     for (u8 j = 0; j < 8; j++)
  25.       if (cut_row(a, i) & cut_col(b, j))
  26.         ans |= 1ull << (8 * i + j);
  27.   return ans;
  28. }
  29.  
  30. u64 at[N], bt[N], ct[N];
  31.  
  32. int main(int argc, char **argv) {
  33.   std::mt19937_64 gen;
  34.   for (int i = 0; i < N; i++) {
  35.     at[i] = gen();
  36.     bt[i] = gen();
  37.   }
  38.  
  39.   for (int i = 0; i < N; i++)
  40.     ct[i] = mul(at[i], bt[i]);
  41.   for (int i = 0; i < 100; i++)
  42.   std::cout
  43.     << std::bitset<64>(at[12421+i]) << '\n'
  44.     << std::bitset<64>(bt[12421+i]) << '\n'
  45.     << std::bitset<64>(ct[12421+i]) << "\n\n";
  46.  
  47.   return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement