Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. * file : problem1.c */
  2. /* author : a.a.ollivier@student.rug.nl */
  3. /* date : Wed Sep 19 2018 */
  4. /* version : 1.0 */
  5.  
  6. /*This program will input a number which corresponds to the position of a superprime number
  7. * and will output the corresponding number. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12.  
  13. int digit[5],initial,var,target;
  14. int i,j,k,l;
  15. int counter,superprime;
  16. int isPrime(int var) {
  17. int k;
  18. for (k=2;k<var;k++) {
  19. if (var % k == 0) {
  20. l = 1;
  21. superprime = 1;
  22. return l;
  23. }
  24. }
  25. }
  26. /*this function figurs out if a number is a prime number or not*/
  27. int main() {
  28. superprime = 0; /* if 0 remains then it is a superprime number */
  29. initial = 10;
  30. counter = 1;
  31. scanf("%d",&target); /* target is the nth superprime that we are looking for */
  32. while ((counter<=target)) {
  33. superprime = 0;
  34. initial = initial + 1;
  35. if ((initial == 11) || (initial == 13) || (initial == 17) || (initial == 31) || (initial == 71)){
  36. initial = initial + 1;
  37. /*the 5 numbers under 100 which consist of one or more '1' are prime numbers n=but cannot be
  38. * superprime since 1 isnt a prime number*/
  39. }
  40. digit[5] = initial/100000;
  41. digit[4] = initial/10000-digit[5]*10;
  42. digit[3] = initial/1000-digit[5]*100-digit[4]*10;
  43. digit[2] = initial/100-digit[5]*1000-digit[4]*100-digit[3]*10;
  44. digit[1] = initial/10-digit[5]*10000-digit[4]*1000-digit[3]*100-digit[2]*10;
  45. digit[0] = initial-digit[5]*100000-digit[4]*10000 -digit[3]*1000-digit[2]*100-digit[1]*10;
  46. l = isPrime(initial);
  47. if (superprime==0) {
  48. for (i = 0;i <= 5;i++) {
  49. digit[5] = initial/100000;
  50. digit[4] = initial/10000-digit[5]*10;
  51. digit[3] = initial/1000-digit[5]*100-digit[4]*10;
  52. digit[2] = initial/100-digit[5]*1000-digit[4]*100-digit[3]*10;
  53. digit[1] = initial/10-digit[5]*10000-digit[4]*1000-digit[3]*100-digit[2]*10;
  54. digit[0] = initial-digit[5]*100000-digit[4]*10000 -digit[3]*1000-digit[2]*100-digit[1]*10;
  55.  
  56. for (j = i;j <= 5;j++) {
  57. digit[j] = digit[j+1];
  58. }
  59. var = 10000*digit[4]+1000*digit[3]+100*digit[2]+10*digit[1]+digit[0];
  60. l = isPrime(var);
  61. if (l == 1) {
  62. superprime = 1;
  63. }
  64. /* this loop figures out if a number is a superprime or not
  65. * the next step is to count the superprime numbers in order to
  66. * give them a position in a list*/
  67. }
  68. }
  69. if (superprime == 0) {
  70. counter++;
  71. }
  72. }
  73. printf("%d \n", initial);
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement