《九日集训》第十三轮(第二讲) 循环

 

 公式法;sizeof(bool[n][n+1])等价于n(n+1)

 
class Solution {

public:

int sumNums(int n) {

return sizeof(bool[n][n+1])>>1;

}

};

 

 

 

 

 

class Solution {public:bool isPowerOfFour(int n) {if(n<=0) return false;int x=(int)(log2(n)/log2(4));if(n-pow(4,x)==0) return true;return

 false;};

3次幂同理 

 
  1. class Solution {

  2. public:

  3. bool isPowerOfThree(int n) {

  4. if(n<=0) return false;

  5. int x=(int)(log2(n)/log2(3));

  6. if(n-pow(3,x)==0) return true;

  7. return false;

  8.  
  9. }

  10. };

 

 

为啥不写在博客里?