Advertisement
llvlleo1810

tìm số đẹp (số tăng giảm)

Aug 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int Nto(int n){
  4. int i;
  5. if(n==1||n==0)
  6. return 0;
  7. for(i=2;i<=sqrt(n);i++)
  8. if(n%i==0)
  9. return 0;
  10. return 1;  
  11. }
  12. int giam(int n){    //xet so giam
  13. int a;
  14. while (n!=0)
  15. {
  16. a=n%10;
  17. n/=10;
  18. if(a>=(n%10))  
  19. return 0;
  20. if(n<=9)
  21. break; 
  22. }
  23. return 1;
  24. }
  25. int tang(int n){    //xet so tang
  26. int a;
  27. while (n!=0)
  28. {
  29. a=n%10;
  30. n/=10;
  31. if(a<=(n%10))
  32. return 0;
  33. if(n<=9)
  34. break; 
  35. }
  36. return 1;
  37. }
  38. int main()
  39. {
  40. int n;
  41. int i;
  42. int dem=0;
  43. scanf("%d",&n);
  44. for(i=pow(10,n-1);i<pow(10,n);i++)
  45. if(Nto(i)&&(tang(i)||giam(i)))
  46. dem++;
  47. printf("%d",dem);  
  48. return 0;  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement