now it seems very hard for me to think more about this problem.
Anyone help me, plz?plzzzzzzzzzzz.
here is my code:
Code: Select all
removed after AC.
Moderator: Board moderators
Code: Select all
removed after AC.
Code: Select all
#include <stdio.h> // 10533 submit
#include <math.h>
#define L 1
#define U 1000005
#define D 1000005
bool all[D];
bool digit[D];
inline void seive(void);
long count[D];
*********removed after AC
/*
12
1 999999
1 1
1 10
9 12
240320 240350
3 20
204525 505639
200 300
1000 3000
2056 31256
999984 999999
999985 999985
OUTPUT:
30123
0
4
1
0
4
9096
8
133
1364
0
0
*/
Your solution's not working for:ayeshapakhi wrote:i wonder wheres the mistake!
pls help!!!
thanks for any help;;;
Code: Select all
10
291188 931733
638630 694459
238760 749751
762142 886106
517246 642611
203388 491378
369474 521162
515894 899808
181906 384967
89477 457040
Code: Select all
18179
1558
14793
3382
3592
8699
4463
10686
6237
11553
Code: Select all
#include<stdio.h>
#include<math.h>
void set_prime(void);
long sod(long);
long prime[10000001];
int main()
{
long tc,t1,t2,j,count;
set_prime();
scanf("%ld",&tc);
while(tc--)
{
scanf("%ld %ld", &t1,&t2);
count = 0;
for(j = t1; j <= t2; j++)
{
if(prime[j])
{
if(prime[sod(j)])
count++;
}
}
printf("%d\n", count);
}
return 0;
}
void set_prime()
{
long i,j,index;
for(i=1;i<=1000000;i++)
prime[i]=1;
prime[1] = 0;
for(i=2;i<=sqrt(1000000);i++)
if(prime[i]==1)
for(j=2;i*j<=1000000;j++)
prime[i*j]=0;
}
long sod(long num)
{
long sum = 0;
while(num)
{
sum += num % 10;
num = num / 10;
}
return sum;
}
Code: Select all
long prime[10000001];
Code: Select all
#define SIZE THE_SIZE_YOU_WANT
char prime[SIZE];
Code: Select all
#define SIZE THE_SIZE_YOU_WANT
char composite[SIZE];
void sieve(void)
{
int i, j, k;
composite[0] = 1;
composite[1] = 1;
for (i=4; i<SIZE; i+=2)
{
composite[i] = 1;
}
for (i=3; i<SIZE; i+=2)
{
if (!composite[i])
{
k = SIZE / i;
for (j=i; j<=k; j+=2)
{
composite[i * j] = 1;
}
}
}
}
Code: Select all
#include<stdio.h>
#define SIZE 1000001
long a,b,data[SIZE]={0},cas,i,j;
void s (void);
long sum_prime(void);
int main()
{
long k,result,cas;
s();
scanf("%ld",&cas);
for(k=1;k<=cas;k++)
{
scanf("%ld %ld",&a, &b);
result=sum_prime();
printf("%ld\n",result);
}
return 0;
}
void s(void)
{
long i,j;
data[0]=1;
data[1]=1;
for(i=4;i<SIZE;i+=2)
data[i]=1;
for(i=3;i<SIZE;i+=2)
for(j=i;i*j<SIZE;j++)
if(!data[i*j])
data[i*j]=1;
}
long sum_prime(void)
{
int sum=0,dum,m=0,z;
for(i=a;i<=b;i++)
if(!data[i])
{
z=i;dum=0;
while(z)
{
m=z%10;
dum +=m;
z /=10;
}
if(!data[dum])
sum++;
}
return sum;
}
Code: Select all
void s(void)
{
long i,j;
data[0]=1;
data[1]=1;
for(i=4;i<SIZE;i+=2)
data[i]=1;
for(i=3;i<SIZE;i+=2)
for(j=2;i*j<SIZE;j++)
{
if(!data[i*j])
data[i*j]=1;
}
}