File size: 1,011 Bytes
c4b0eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/*
math > number theory > prime numbers > prime factorization
difficulty: easy
date: 13/Feb/2020
by: @brpapa
*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int sumDigits(int n) {
int sum = 0;
while (n > 0) {
sum += n%10;
n /= 10;
}
return sum;
}
int main() {
int T; cin >> T;
while (T--) {
int n; cin >> n;
for (int ans = n+1; true; ans++) {
int tmp = ans; vector<int> ansFactors;
for (int f = 2; f <= sqrt(tmp) && tmp > 0; f++)
while (tmp%f == 0) {
ansFactors.push_back(f);
tmp /= f;
}
if (ansFactors.empty()) continue; // ans é primo, logo não é smith
if (tmp > 1) ansFactors.push_back(tmp);
int sumFactorsDigits = 0;
for (int f: ansFactors) sumFactorsDigits += sumDigits(f);
if (sumDigits(ans) == sumFactorsDigits) {
cout << ans << endl; break;
}
}
}
return 0;
}
|