Ad
Code
Diff
  • package kata
    
    func IntegerSum(n int) (sum int) {
      sum = n * (n+1) / 2
      return
    }
    
    func AddMultiples(n int) (sum int) {
      sum = IntegerSum((n-1)/3) * 3 + IntegerSum((n-1)/5) * 5 - IntegerSum((n-1)/15) * 15
      return 
    }
    • package kata
    • func AddMultiples(n int) (sum int) {
    • for i := 1; i < n; i++ {
    • if i % 3 == 0 || i % 5 == 0 {
    • sum += i
    • }
    • }
    • func IntegerSum(n int) (sum int) {
    • sum = n * (n+1) / 2
    • return
    • }
    • func AddMultiples(n int) (sum int) {
    • sum = IntegerSum((n-1)/3) * 3 + IntegerSum((n-1)/5) * 5 - IntegerSum((n-1)/15) * 15
    • return
    • }
Code
Diff
  • unsigned long long div2(unsigned long long a){
      
      return a >> 1;
    }
    • unsigned long long div2(unsigned long long a){
    • return a * 5 / 10;
    • return a >> 1;
    • }
Code
Diff
  • bool isLeap(long n) {
        return (n % 4 == 0 && n % 100 != 0) || (n % 400 == 0);
    }
    • bool isLeap(long n) {
    • if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
    • return true;
    • return false;
    • return (n % 4 == 0 && n % 100 != 0) || (n % 400 == 0);
    • }