Hi.
I'm trying to solve this problem (spoj.pl/problems/DIVSUM/) but I get WA. I try to build the dividers from the prime factors and taste different inputs and I think my answer is correct.
My WA Code:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <set>
using namespace std;
int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
653, 659, 661, 673, 677, 683, 691, 701, 709, 0 };
int main() {
int N, K;
scanf ("%d", &N);
while (N--) {
scanf ("%d", &K);
if (!K || K == 1) {
puts ("0");
continue;
}
int T = K;
vector<int> f;
set<int> divs;
for (int* ptr = &primes[0]; *ptr && ptr && K > 1; ++ptr) {
while (!(K % *ptr))
f.push_back (*ptr), K /= *ptr;
}
divs.insert (1);
for (size_t i = 0; i < f.size(); ++i)
if (f[i] != T) divs.insert (f[i]);
for (size_t z = 0; z < f.size(); ++z) {
int _t = 1;
for (size_t i = z; i < f.size() - 1; ++i) {
_t *= f[i];
for (size_t k = i + 1; k < f.size(); ++k)
if (_t * f[k] < T) divs.insert (_t * f[k]);
}
}
unsigned long long answer = 0;
for (set<int>::iterator it = divs.begin(); it != divs.end(); ++it)
answer += *it;
printf ("%llu\n", answer);
}
return 0;
}