kanatunta

3ta.telerik.ver.3

Feb 25th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////////////////////////////////////////////////////
  2. const getGets = arr => {
  3.   let index = 0;
  4.  
  5.   return () => {
  6.     const toReturn = arr[index];
  7.     index += 1;
  8.     return toReturn;
  9.   };
  10. };
  11. // this is the test
  12. const test = ["100 200"];
  13.  
  14. const gets = this.gets || getGets(test);
  15. const print = this.print || console.log;
  16.  
  17. //////////////////////////////////////////////////////////////////////////
  18.  
  19. const [row, col] = gets()
  20.   .split(" ")
  21.   .map(Number);
  22.  
  23. //console.log(row, col);
  24.  
  25. const isInside = (r, c) => {
  26.   let result = false;
  27.   if (r > 0 && c > 0 && r < row - 1 && c < col - 1) result = true;
  28.   return result;
  29. };
  30.  
  31. let sum = 0n;
  32. const two = 2n;
  33. if (row !== col) {
  34.   for (let r = 0; r < row; r++) {
  35.     for (let c = r % 2 ? 1 : 0; c < col; c += 2) {
  36.       //console.log(r, c);
  37.       let temp = two ** BigInt(r + c);
  38.       if (isInside(r, c)) {
  39.         temp += temp;
  40.       }
  41.       sum += temp;
  42.     }
  43.   }
  44. } else {
  45.   for (let i = 0; i < row; i++) {
  46.     let temp = two ** BigInt(r + c);
  47.     //console.log(temp);
  48.     sum += temp;
  49.   }
  50. }
  51.  
  52. print(sum.toString());
Advertisement
Add Comment
Please, Sign In to add comment