All pastes #82966 Raw Edit

Mine

public text v1 · immutable
·published 2006-07-09 04:52 UTC
rendered paste body
//To be compiled on gcc

//#include <iostream.h>
#include <math.h>

double f,m,n,p,t,previous,trial;

int twinprimes()
{
	
	
		trial = p;
			
			//check for prime
			while(trial != 0)
			   {
		
				   f=0;
				   t=3;
		
				   while( t*t <= trial)
				   {
					   //cout << "debug	" << t*t << "	" << trial << endl;
					   if(fmod(trial,2) == 0)  // if trial is even
					   {
						   f = 2;
						   p -= 1; // make p odd
					   }
						if (fmod(trial,t) == 0)
						{	
							
							f=t;
							t=trial;
							
						}
						else
						t=t+2;
				   }
		
				   if (f == 0)
					{
						   printf ("%d is a prime number.\n",trial);
						   trial = 0;
						//is previous 1?
						if(previous == 1)
						{
		
						//cout << p-2 << ", " << p << " are twin primes!" << endl;
		                                printf("%d, %d are twin primes!\n", p-2, p);
						}
						else
						{
		
							previous = 1;
		
						}
					}
				   else 
					{
						   //cout << trial << " has a factor of " << f << "." << endl;
                                                   printf("%d has a factor of %d.\n", trial, f);
						   
trial = 0;
						previous = 0;
					}
				   
			   }
			
			p += 2;

			if(p <= m)
			{
				return 1; //repeat
			}
			else
			{
				return 2; //complete
			}
}


int main()
{
	int q;

		//input
		//cout << "Enter the lower limit for a ranged twin prime # check..." << endl;
                printf("Enter the lower limit for a ranged twin prime # check...\n");
		scanf("%d", &n);
                //cin >> n;
		if(n < 7)
		{

			printf("The lower limit must be greater than or equal to 7\n");
			return 0;
		}
		printf("Enter the upper limit for a ranged twin prime # check...\n");
		//cin >> m;
                scanf("%d", &m);
		if(m < n + 2)
		{

			printf("The upper limit must be greater than or equal to %d\n", n + 2);
			return 0;
		}
		
		p = n;
		previous = 0;
		f = 0;

		while(q != 2)
		{
			q = twinprimes();
		}
		
	return 0;
}