Thursday, October 20, 2016

Euler001 : Finding sum of multiples of 3 or 5

problem
Comments :
This code is only partially correct. It  has to be made more efficient. Two test cases have not been passed. Time limit exceed, otherwise the algorithm is correct.
Code :
#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        long long int num;
        cin>>num;
        long long int i, sum = 0;
        for(i=1;i<num;i++){
            if((i%3==0)||(i%5==0)){
                sum = sum+i;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

No comments:

Post a Comment

Search This Blog