Multiples of 3 or 5
This is a programming version of Problem 1 from projecteuler.net.
#include <bits/stdc++.h>using namespace std;
int main() { int t; cin >> t; for (int a0 = 0; a0 < t; a0++) { int n; cin >> n; n--;
long long ans = 0; long long a = n / 3;
a = (3 * a * (a + 1)) / 2; ans += a;
a = n / 5; ans += (a * (a + 1) * 5) / 2;
a = n / 15; ans -= (15 * a * (a + 1)) / 2;
cout << ans << "\n"; } return 0;}Give it a try first
Attempt the problem on HackerRank — the code will still be here.