fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool is_prime(int k) {
  4. if(k < 2) return 0;
  5. for(int i = 2; i <= sqrt(k); i++)
  6. if(k % i == 0) return 0;
  7. return 1;
  8. }
  9. bool check_prime(int k) {
  10. if(is_prime(k)) return 1;
  11. return 0;
  12. }
  13. bool check_sum_prime(int k) {
  14. int s = 0;
  15. while(k != 0){
  16. s += k % 10;
  17. k /= 10;
  18. }
  19. if(is_prime(s)) return 1;
  20. return 0;
  21. }
  22. bool check_element(int k) {
  23. while(k != 0) {
  24. if(!is_prime(k % 10)) return 0;
  25. k /= 10;
  26. }
  27. return 1;
  28. }
  29. bool check_n(int k, int n) {
  30. int d = 0;
  31. while(k != 0) {
  32. k /= 10;
  33. d++;
  34. }
  35. if(d == n) return 1;
  36. return 0;
  37. }
  38. int main() {
  39. int k, n;
  40. cin >> k >> n;
  41. if(check_n(k, n)) cout << k << " co " << n << " chu so" << endl;
  42. if(check_sum_prime(k)) cout << k << " co tong cac chu so la so nguyen to" << endl;
  43. if(check_prime(k)) cout << k << " la so nguyen to" << endl;
  44. if(check_element(k)) cout << k << " co cac chu so la so nguyen to" << endl;
  45. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty