fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <map>
  4. #include <set>
  5. #include <cmath>
  6. #include <vector>
  7. #include <climits>
  8. #include <string>
  9. #include <algorithm>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. vector<string> split(string haystack, string needle) {
  14. vector<string> result;
  15. int startPos = 0;
  16. int foundPos = haystack.find(needle, startPos);
  17. while (foundPos != string::npos) {
  18. int count = foundPos - startPos;
  19. string token = haystack.substr(startPos, count);
  20. if (!token.empty()) {
  21. result.push_back(token);
  22. }
  23. startPos = foundPos + needle.length();
  24. foundPos = haystack.find(needle, startPos);
  25. }
  26. string token = haystack.substr(startPos, haystack.length() - startPos);
  27. if (!token.empty()) {
  28. result.push_back(token);
  29. }
  30. return result;
  31. }
  32.  
  33. string nameConvert(const string& name) {
  34. const string DELIMITER = " ";
  35. stringstream builder;
  36. auto parts = split(name, DELIMITER);
  37. for (auto part : parts) {
  38. part[0] = toupper(part[0]);
  39. transform(part.begin() + 1, part.end(), part.begin() + 1, ::tolower);
  40. builder << part << DELIMITER;
  41. }
  42. return builder.str();
  43. }
  44.  
  45. string dateConvert(const string& date) {
  46. const string DELIMITER = "/";
  47. stringstream builder;
  48. auto parts = split(date, DELIMITER);
  49. builder << setw(2) << setfill('0') << parts[0] << DELIMITER;
  50. builder << setw(2) << setfill('0') << parts[1] << DELIMITER;
  51. builder << parts[2];
  52. return builder.str();
  53. }
  54.  
  55. bool isPrime(long long n) {
  56. for (int i = 2;i * i <= n;i++) {
  57. if (n % i == 0) {
  58. return false;
  59. }
  60. }
  61. return n >= 2;
  62. }
  63.  
  64. bool isAllDigitPrime(string n) {
  65. for (int i = 0;i < n.length();i++) {
  66. if (n[i] != '2' && n[i] != '3' && n[i] != '5' && n[i] != '7') {
  67. return false;
  68. }
  69. }
  70. return true;
  71. }
  72.  
  73. bool isSumDigitPrime(string n) {
  74. long long sum = 0;
  75. for (int i = 0;i < n.length();i++) {
  76. sum = sum + (n[i] - '0');
  77. }
  78. return isPrime(sum);
  79. }
  80. int main() {
  81. ios_base::sync_with_stdio(false);
  82. cin.tie(NULL);
  83.  
  84. string n;cin >> n;
  85. if (isAllDigitPrime(n) && isSumDigitPrime(n)) {
  86. cout << "YES";
  87. }
  88. else {
  89. cout << "NO";
  90. }
  91. return 0;
  92. }
  93.  
  94.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
NO