Problem Link

This code adds all numbers from 1 to the input value that are divisible by 3 or 5. For the problem’s limit of below 1000, use 999 as the input.

#include <iostream>
using namespace std;
 
void solve(void) {
  int n; cin >> n;
 
  int ans = 0;
  for (int i=1; i<=n; i++) {
    if (!(i % 3) || !(i % 5)) ans += i;
  }
  cout << ans;
}
 
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
 
  solve();
  return 0;
}