fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define MAX 25
  5.  
  6. int primes[MAX] = {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};
  7. int possSums[100];
  8. int possSumCount = 0;
  9.  
  10. int sumAcheived[100];
  11.  
  12. bool isPrime(int n) {
  13. for(int i = 0; i < MAX; i++)
  14. if(primes[i] == n) return true;
  15.  
  16. return false;
  17. }
  18.  
  19. bool canBeSumOfPrimes(int n) {
  20. for(int i = 2; i < n - 1; i++)
  21. if(isPrime(i) && isPrime(n - i)) return true;
  22.  
  23. return false;
  24. }
  25.  
  26. bool isPossSum(int n) {
  27. for(int i = 0; i < possSumCount; i++)
  28. if(possSums[i] == n) return true;
  29.  
  30. return false;
  31. }
  32.  
  33. int main() {
  34.  
  35. for(int i = 5; i < 100; i++)
  36. if(!canBeSumOfPrimes(i)) possSums[possSumCount++] = i;
  37.  
  38.  
  39. for(int i = 5; i < 2500; i++) {
  40. int psCount = 0, ps1 = 0, ps2 = 0;
  41. for(int j = 1; j*j <= i; j++) {
  42. if(i % j == 0) {
  43. if(isPossSum(j + (i/j))) {
  44. ps1 = j;
  45. ps2 = i/j;
  46. psCount++;
  47. }
  48. }
  49. }
  50.  
  51. if(psCount == 1) sumAcheived[ps1 + ps2]++;
  52. }
  53.  
  54. for(int i = 0; i < 100; i++) {
  55. if(sumAcheived[i] == 1) {
  56. cout << "Sum = " << i << endl;
  57. break;
  58. }
  59. }
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Sum = 17