fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. #define MAX 100
  5.  
  6. void NhapmangSNT(int a[], int &n);
  7. int SoPhanTuChuaY(int a[], int n, int y);
  8.  
  9. void NhapmangSNT(int a[], int &n)
  10. {
  11. return;
  12. }
  13.  
  14. bool checknum(int n, int k)
  15. {
  16. while(n > 0)
  17. {
  18. if(k == int(n % 10))
  19. return true;
  20. n /= 10;
  21. }
  22. return false;
  23. }
  24.  
  25. bool checkprime(int n)
  26. {
  27. if(n < 2)
  28. return false;
  29. for(int i = 2; i <= int(sqrt(n)); i++)
  30. if(n % i == 0)
  31. return false;
  32. return true;
  33. }
  34.  
  35. int SoPhanTuChuaY(int a[], int n, int y)
  36. {
  37. cin >> n;
  38. int arr[10001], dem = 1, ans = 0;
  39. for(int i = 2; i <= 10001; i++)
  40. if(dem <= n)
  41. if(checkprime(i))
  42. {
  43. if(checknum(i, y))
  44. ans++;
  45. dem++;
  46. }
  47. return ans;
  48. }
  49.  
  50. int main()
  51. {
  52. int a[MAX], n, y;
  53. cin >> y;
  54. NhapmangSNT(a, n);
  55. cout << SoPhanTuChuaY(a, n, y) << endl;;
  56. return 0;
  57. }
  58.  
  59.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0