a53

TruncatableLeft

a53
Jan 1st, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool is_prime(int x){
  6. if(x < 2)
  7. return 0;
  8. if(x != 2 && x % 2 == 0)
  9. return 0;
  10. for(int d = 3; d * d <= x; d += 2)
  11. if(x % d == 0)
  12. return 0;
  13. return 1;
  14. }
  15.  
  16. int nr_digits(int x)
  17. {
  18. int cnt = 0;
  19. do{
  20. x /= 10;
  21. cnt++;
  22. }
  23. while(x);
  24. return cnt;
  25. }
  26.  
  27. int pow10(int x)
  28. {
  29. int r = 1;
  30. for(;x;--x)
  31. r *= 10;
  32. return r;
  33. }
  34.  
  35. void removeFirstDigit(int &n)
  36. {
  37. if(n < 9)
  38. {
  39. n = 0;
  40. return;
  41. }
  42. int nrdig = nr_digits(n);
  43. n = n % pow10(nrdig - 1);
  44. }
  45. int main()
  46. {
  47. int n; cin >> n;
  48. bool pp = true;
  49.  
  50. while(n)
  51. {
  52. if(!is_prime(n))
  53. pp = false;
  54. removeFirstDigit(n);
  55. }
  56.  
  57. cout << (pp ? "DA" : "NU");
  58. return 0;
  59. }
Add Comment
Please, Sign In to add comment