Files
contests/misc/others/other.cpp

64 lines
954 B
C++

#include <cmath>
#include <iostream>
using namespace std;
bool isComposite(int n) {
if (n <= 1) {
return false;
}
if (n <= 3) {
return false;
}
if (n % 2 == 0 || n % 3 == 0) {
return true;
}
int i = 5;
while (i * i <= n) {
if (n % i == 0 || n % (i + 2) == 0) {
return true;
}
i = i + 6;
}
return false;
}
int getSum(int n) {
int s = 0;
while (n > 0) {
s += n % 10;
n /= 10;
}
return s;
}
int getPrimeSum(int n) {
int s = 0;
while (n % 2 == 0) {
s += 2;
n /= 2;
}
for (int i = 3; i <= sqrt(n); i += 2) {
while (n % i == 0) {
s += getSum(i);
n /= i;
}
}
if (n > 2) {
s += getSum(n);
}
return s;
}
int main() {
int n;
cin >> n;
while (true) {
if (getSum(n) == getPrimeSum(n)) {
if (getPrimeSum(n) != 0) {
if (isComposite(n)) {
break;
}
}
}
n += 1;
}
cout << n << endl;
return 0;
}