Microsoft Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

Factorial prime:
Its a prime number that is 1 less or 1 more than a factorial.
e.g

2 (0! + 1 or 1!+1)
       3(2! +1) ....

Also, what the OP meant was prime "factors" and not prime "factorials"

- chandershivdasani August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

int count;

void check_factorial_prime(int var)
{
	int a=sqrt(var-1);
	int b=sqrt(var+1);
	int i;
	for(i=2;i<=a;i++)
	{
		if((var-1)%i==0)
			break;
	}
	if(i==a+1)
	{
		cout << var-1<<endl;
		count++;
	}
	for(i=2;i<=b;i++)
	{
		if((var+1)%i==0)
			break;
	}
	if(i==b+1)
	{
		cout << var+1<<endl;
		count++;
	}
}

int main()
{
	int n;
	cout << "Enter n : ";
	cin >> n;
	int i=3;
	count=2;
	int mult=2;
	if(n==1)
		cout << "2\n";
	else
	{
		cout << "2\n";
		cout << "3\n";
		while(count!=n)
		{
			mult=mult*(i++);
			check_factorial_prime(mult);
		}
	}
	return 0;
}

- maverick August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can any body please explain the problem. i am not getting the Question.

- Aalok August 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static void getFactorialPrimes(int N)
    {
        BigInteger factorial= new BigInteger("1");
        BigInteger one= new BigInteger("1");
        for(int i=0, nextNum=1; i<N;)
        {
            if(factorial.subtract(one).isProbablePrime(100))
            {
                System.out.println(factorial.subtract(one).toString());
                i++;
            }
            if(factorial.add(one).isProbablePrime(100))
            {
                System.out.println(factorial.add(one).toString());
                i++;
            }
            factorial= factorial.multiply(new BigInteger(""+(++nextNum)));
        }
    }

- nj August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pls make the question little more clear. what do you mean by "factorial primes"?

- Anand August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

there is no number whose factorial is prime (other than 2)
yanna rascala. .. make the question clear!

- rajnikant August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

while(i<N)
{
fact=factorial(i) ;
if(is_prime(fact-1))
printf("%d",fact-1) ;
if(is_prime(fact+1) )
printf("%d",fact-1) ;
}

- Anonymous August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

forgor to increment i;
hence befoe ending loop i++;

- Anonymous August 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A factorial prime is a prime number that is one less or one more than a factorial (all factorials above 1 are even). The first few factorial primes are:
2 (0! + 1 or 1! + 1), 3 (2! + 1), 5 (3! − 1), 7 (3! + 1), 23 (4! − 1), 719 (6! − 1), 5039 (7! − 1), 39916801 (11! + 1)

- rahul August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1] Generate a primes bool map using sieve to cover the maximum possible range

2] Start generating factorials checking the primes map for fact -+ 1 every time and decrements N whenever you find a true

- Mustapha November 30, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More