Advertisement
Imran1107048

1(b) Twin Prime & Prime Factor

Oct 29th, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<stdbool.h>
  4.  
  5. bool array[50];
  6. bool arr[50];
  7.  
  8. bool Perplexing_Primes(int n)
  9. {
  10. if(n<=1)
  11. return false;
  12. if(n==2)
  13. return true;
  14. if(n>2 && n%2==0)
  15. return false;
  16. int div = sqrt(n);
  17. for(int i=3;i<=div;i+=2)
  18. if(n%i==0)
  19. return false;
  20. return true;
  21. }
  22.  
  23. void Multiplicated_Value(int n)
  24. {
  25. while(n%2 == 0){
  26. arr[2] = true;
  27. n/=2;
  28. }
  29. for(int i= 3; i<=sqrt(n);i+=2){
  30. while(n%i==0){
  31. arr[i] = true;
  32. n/=i;
  33. }
  34. }
  35. if(n>2)
  36. arr[n] = true;
  37. }
  38.  
  39. int main()
  40. {
  41. int n = (55 % 5) + 31;
  42. for(int i=1;i<n+4;i++){
  43. array[i] = Perplexing_Primes(i);
  44. }
  45. for(int i=1;i<=n;i++){
  46. if(array[i] == true && array[i+2] == true){
  47. array[i] = true;
  48. array[i+2] = true;
  49. i+=2;
  50. }
  51. else
  52. array[i] = false;
  53. }
  54. Multiplicated_Value(n);
  55. bool ok = false;
  56. for(int i=1;i<=n;i++){
  57. if(array[i] == true && arr[i] == true){
  58. ok = true;
  59. printf("%d is a twin prime!\n", i);
  60. }
  61. }
  62.  
  63. if(!ok){
  64. printf("No twin prime there\n");
  65. }
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement