BobbyCodes

Welcome to My Coding Blog

HackerRank Euler Problem 002

Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler002/problem If you don’t understand, you can reply in comments. #include <iostream> using namespace std; int main(){     int t;     cin >> t;     for(int a0 = 0; a0 < t; a0++){         long n;         cin >> n;         long long int a = 1,b = 2,c = 0, sum = 0;         while(b < n)         {             if(b%2==0)             sum+=b;             c=a+b;             a=b;             b=c;         }         cout << sum << endl;     }   return 0; }

HackerRank Euler Problem 001

Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler001/problem int main(){     int t;     cin >> t;     for(int a0 = 0; a0 < t; a0++){         long long int n;         cin >> n;         n–;         long long int sum=0;                  long long int n3=n/3;         long long int n5=n/5;         long long int n15=n/15;                  long long int val3=3*(n3*(n3+1))/2;         long long int val5=5*(n5*(n5+1))/2;         long long int val15=15*(n15*(n15+1))/2;         sum = val3 + val5 – val15;         cout<<sum<<endl;     }     return 0; } If you didn’t get the solution, you can comment here.


Follow My Blog

Get new content delivered directly to your inbox.

Design a site like this with WordPress.com
Get started