Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * file : problem1.c */
- /* author : a.a.ollivier@student.rug.nl */
- /* date : Wed Sep 19 2018 */
- /* version : 1.0 */
- /*This program will input a number which corresponds to the position of a superprime number
- * and will output the corresponding number. */
- #include <stdio.h>
- #include <stdlib.h>
- int digit[5],initial,var,target;
- int i,j,k,l;
- int counter,superprime;
- int isPrime(int var) {
- int k;
- for (k=2;k<var;k++) {
- if (var % k == 0) {
- l = 1;
- superprime = 1;
- return l;
- }
- }
- }
- /*this function figurs out if a number is a prime number or not*/
- int main() {
- superprime = 0; /* if 0 remains then it is a superprime number */
- initial = 10;
- counter = 1;
- scanf("%d",&target); /* target is the nth superprime that we are looking for */
- while ((counter<=target)) {
- superprime = 0;
- initial = initial + 1;
- if ((initial == 11) || (initial == 13) || (initial == 17) || (initial == 31) || (initial == 71)){
- initial = initial + 1;
- /*the 5 numbers under 100 which consist of one or more '1' are prime numbers n=but cannot be
- * superprime since 1 isnt a prime number*/
- }
- digit[5] = initial/100000;
- digit[4] = initial/10000-digit[5]*10;
- digit[3] = initial/1000-digit[5]*100-digit[4]*10;
- digit[2] = initial/100-digit[5]*1000-digit[4]*100-digit[3]*10;
- digit[1] = initial/10-digit[5]*10000-digit[4]*1000-digit[3]*100-digit[2]*10;
- digit[0] = initial-digit[5]*100000-digit[4]*10000 -digit[3]*1000-digit[2]*100-digit[1]*10;
- l = isPrime(initial);
- if (superprime==0) {
- for (i = 0;i <= 5;i++) {
- digit[5] = initial/100000;
- digit[4] = initial/10000-digit[5]*10;
- digit[3] = initial/1000-digit[5]*100-digit[4]*10;
- digit[2] = initial/100-digit[5]*1000-digit[4]*100-digit[3]*10;
- digit[1] = initial/10-digit[5]*10000-digit[4]*1000-digit[3]*100-digit[2]*10;
- digit[0] = initial-digit[5]*100000-digit[4]*10000 -digit[3]*1000-digit[2]*100-digit[1]*10;
- for (j = i;j <= 5;j++) {
- digit[j] = digit[j+1];
- }
- var = 10000*digit[4]+1000*digit[3]+100*digit[2]+10*digit[1]+digit[0];
- l = isPrime(var);
- if (l == 1) {
- superprime = 1;
- }
- /* this loop figures out if a number is a superprime or not
- * the next step is to count the superprime numbers in order to
- * give them a position in a list*/
- }
- }
- if (superprime == 0) {
- counter++;
- }
- }
- printf("%d \n", initial);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement