Problem 1
set を使っているのは単に使ってみたかっただけです.
#include <iostream> #include <set> using namespace std; #define NUM 1000 int main(int argc, char **argv) { set<int> s; for (int i = 3; i < NUM; i+=3) { s.insert(i); } for (int i = 5; i < NUM; i+=5) { s.insert(i); } int sum = 0; for (set<int>::iterator it = s.begin(), e = s.end(); it != e; it++) { sum += *it; } cout << sum << endl; return 0; }