10110 - Light, More Light

All about problems in Volume CI. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Re: 10110 - Light, More Light

Postby sauro » Wed Nov 09, 2011 9:53 pm

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
Location: BUET, bangladesh

Re: 10110 - Light, More Light

Postby shuvrothpol1 » Thu Nov 15, 2012 2:50 am

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

Postby brianfry713 » Thu Nov 15, 2012 10:25 pm

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

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 1 guest