Ad
Code
Diff
  • function calculate_multiples ($limit){
    
      $t= [Math]::floor($limit/3)
      $f= [Math]::floor($limit/5)
      $tf=[Math]::floor($limit/15)
      return (($t/2)*($t+1)*3)+(($f/2)*($f+1)*5)-(($tf/2)*($tf+1)*15)
    }
    • function calculate_multiples {
    • function calculate_multiples ($limit){
    • $SUM = 0
    • 1..999 | ForEach-Object {
    • if (!( $_ % 3) -OR !($_ % 5)) {
    • $Sum += $_
    • }
    • }
    • return $Sum
    • $t= [Math]::floor($limit/3)
    • $f= [Math]::floor($limit/5)
    • $tf=[Math]::floor($limit/15)
    • return (($t/2)*($t+1)*3)+(($f/2)*($f+1)*5)-(($tf/2)*($tf+1)*15)
    • }