## 10110 - Light, More Light

Moderator: Board moderators

### Re: 10110 - Light, More Light

shahedcsenu wrote:i cNT UNDERStand the problem...when light on and when off .;.plz anyone can explain it??

check my earlier post.
all that we see or seem is but a dream within a dream
sauro
New poster

Posts: 4
Joined: Mon Aug 30, 2010 11:26 pm

### Re: 10110 - Light, More Light

runtime error...why??? (also tried with long long )

#include <stdio.h>
#include <math.h>
#define N 70000

unsigned int status[N+1]={0},prime[N+1];
void list_prime();
unsigned int primefactor(unsigned int n);

int main ()
{
unsigned int n;
list_prime();
scanf ("%u",&n);
while (n!=0){
if (n%2==0)
printf ("yes\n");
else if (status[n]==0)
printf ("no\n");
else
{
n=primefactor(n)+1;
if (n%2==0)
printf ("no\n");
else
printf ("yes\n");
}
scanf ("%u",&n);
}
return 0;
}

void list_prime() {
unsigned int i, j, sqrtN;

sqrtN = sqrt( N );
for( i = 3; i <= sqrtN; i += 2 ) {
if( status[i] == 0 ) {
for( j = i * i; j <= N; j += i + i )
status[j] = 1;
}
}
prime[0]=2;
status[1]=1;
j=1;
for( i = 3; i <= N; i += 2 ) {
if( status[i] == 0 ){
prime[j++]=i;
}
}
}

unsigned int primefactor(unsigned int n)
{
unsigned int listSize=0,i,j;
unsigned int sqrtN =sqrt(n);
for(i = 0; prime[i] <= sqrtN; i++ ) {
if( n % prime[i] == 0 ) {
while( n % prime[i] == 0 ) {
n /= prime[i];
listSize++;
}
}
}
if( n > 1 ) {
listSize++;
}
return listSize;
}
shuvrothpol1
New poster

Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

### Re: 10110 - Light, More Light

It looks like you figured it out.
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous