Advertisement
0945928233

Tìm số đẹp (số nguyên tố và có tổng các chữ số là một số tr

Jun 19th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <ctype.h>
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7.  
  8. int ngto(int n)
  9. {
  10. if(n==0||n==1) return 0;
  11. if(n==2) return n;
  12. else
  13. {
  14. int i,dem=0;
  15. for(i=2;i<n;i++)
  16. {
  17. if(n%i==0) dem++;
  18. }
  19. if(dem>0) return 0;
  20. else return n;
  21. }
  22. }
  23. int fibo(int n)
  24. {
  25. if(n==0||n==1) return n;
  26. else return fibo(n-1)+fibo(n-2);
  27. }
  28. int socantim(int n)
  29. {
  30. int i=0,dem=0;
  31. while(fibo(i)<=n)
  32. {
  33. if(fibo(i)==n)
  34. {
  35. dem++;
  36. return n;
  37. }
  38. i++;
  39.  
  40. }
  41. if(dem==0) return 0;
  42. }
  43. int tongchuso(int n)
  44. {
  45. int a,b=0;
  46. while(n>0)
  47. {
  48. a=n%10;
  49. b=b+a;
  50. n/=10;
  51. }
  52. return b;
  53. }
  54. int main()
  55. {
  56. int a,b;
  57. scanf("%d%d",&a,&b);
  58. if(a>b)
  59. {
  60. a=a+b;
  61. b=a-b;
  62. a=a-b;
  63. }
  64. int i;
  65. for(i=a;i<=b;i++)
  66. {
  67. if(i==ngto(i)&&i!=0&&tongchuso(i)==socantim(tongchuso(i))) printf("%d ",i);
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement