Project Euler #1: Multiples of 3 and 5

  • + 0 comments

    int main(){ int t; cin >> t; for(int a0 = 0; a0 < t; a0++){ int n; cin >> n; long long sum=0;

    long  i= (n-1)/3 ,j = (n-1)/5 , k=(n-1)/15;
    sum= 3*(i*(i+1)/2)+ 5*(j*(j+1)/2) - 15*(k*(k+1)/2);
    
    cout<<sum<<"\n";
        }