fork download
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int checkn(int k, int n)
  6. {
  7. int i=0;
  8. while(k>0)
  9. {
  10. i++;
  11. k=k/10;
  12. }
  13. if (i==n) return 1;
  14. return 0;
  15. }
  16.  
  17. int nguyento(int k)
  18. {
  19. for(int i=2;i*i<=k;i++)
  20. {
  21. if(k%i==0) return 0;
  22. }
  23. return 1;
  24. }
  25.  
  26. int tong(int k)
  27. {
  28. int tong;
  29. while(k>0)
  30. {
  31. tong=tong+k%10;
  32. k=k/10;
  33. }
  34. if(nguyento(tong)) return 1;
  35. return 0;
  36. }
  37.  
  38. int chuso(int k)
  39. {
  40. while(k>0)
  41. {
  42. if(nguyento(k%10)==0) return 0;
  43. k=k/10;
  44. }
  45. return 1;
  46. }
  47.  
  48. int main()
  49. {
  50. int k, n; cin>>k>>n;
  51. if(checkn(k,n)&&nguyento(k)&&tong(k)&&chuso(k))
  52. cout<<"YES\n";
  53. else cout<<"NO\n";
  54. return 0;
  55. }
  56.  
  57.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
NO