Beispiel #1
0
int main()
{
	seive();
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==1)printf("%d\n",n);
		else
		{
			printf("1");
			if(a[n]!=0)
			{
				while(n%a[n]==0)
				{
					printf(" x %d",a[n]);
					if(a[n]==0)
						break;
					n=n/a[n];
					if(a[n]==0)
						break;
				}
			}
			printf(" x %d\n",n);
		}
	}
	return 0;
}
Beispiel #2
0
/*
 *素性测试,对sqrt(n)内的素数进行测试即可,预处理求出sqrt(n)中的素数,
 *假设该范围内素数的个数为s,那么复杂度降为O(s)。
 */
bool is_prime(int x)   {
    int p = seive (sqrt (x + 0.5));
    for (int i=1; i<=p; ++i) {
        if (x % prime[i] == 0) {
            return false;
        }
    }
    return x != 1;
}
Beispiel #3
0
int main()
{
    int t, n;
    seive(MAX_NUM);
    scanf("%d", &t);
    while (t--){
        scanf("%d", &n);
        printf("%d\n", euler_totient(n));
    }
    return 0;
}
Beispiel #4
0
int main()
{
	int num;
	seive();
	while(1)
	{
		scanf("%d",&num);
		if(num == 0)
			break;
		calcfactors(num);
	}
	return 0;
}	
int main()
{
    long long  n,i,max,j;
     seive(10000100);
     while(1)
     {
		 scanf("%lld",&n);
		 if(n==0)
			 break;
         j=0;
         max=0;
         if(n==1||n==-1)
         {
            printf("-1\n");
            continue;
         }
         if(n<0)
			 n=-n;
         for(i=0;i<c&&n>=a[i];)
         {
           if(n%a[i]==0)
           {
               n=n/a[i];
               if(a[i]>max)
               {
                  max=a[i];
                  j++;
               }
            }
           else
           {
              i++;
           }
         }
		 if(n!=1&&j==0)
		 {
			 printf("-1\n");
			 continue;
		 }
		 if(n!=1)
		 {
			 printf("%lld\n",n);
			 continue;
		 }
         if(j==1)
            printf("-1\n");
         else 
			printf("%lld\n",max);
       }
       return 0;
}
Beispiel #6
0
int main()
{
	seive();
	pre();
	while(scanf("%ld",&n)!=EOF)
	{
		long cnt=0;
		for(i=1;i<=n;i++)
		{
			scanf("%ld",&a);
			if(prime[a]==1)
				cnt++;
		}
		printf("%ld\n",cnt);
	}
	return 0;
}
Beispiel #7
0
int main()
{
	
	int num,i;
	for(i=0;i<n;i++)
		cum[i] = 0;
	seive();
	while(1)
	{
		if(scanf("%d",&num)==EOF)
			break;
		if(num == 0)
			break;
		calcfactors(num);
	}
	return 0;
}	
Beispiel #8
0
main()
{
	int tc,t1,t2;
	seive(1002001);
	scanf("%d",&tc);
	while(tc--)
	{
		scanf("%d %d",&t1,&t2);
		if(t1==1 && t2==1)printf("0\n");
		else
		{
			while(!prime[t1])t1++;
			while(!prime[t2])t2--;
			printf("%d\n",prime[t2]-prime[t1]+1);
		}
	}
}
Beispiel #9
0
int main()
{
int i,t;
seive();
ar[0]=0;
ar[1]=0;
//f();
for(i=2;i<=max;i++)
ar[i]=ar[i-1]+aa[i];
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("%lld\n",ar[n]);
}
return 0;
}
int main(void)
{
	seive();

	long long n, temp, count, i, root ;

	while(scanf("%lld",&n)==1)
	{
		if(n==0||n==1)
		{
			printf("1\n");
			continue;
		}

		else if(n<=30000000 && flag[n]==false)
		{
			printf("2\n");
			continue;
		}
		
		count = 1 ;

		root = sqrt(n);

		for(i=0;prime[i]<=root;i++)
		{
			temp = 1;
			
			for(;n%prime[i]==0;)
			{
				n/=prime[i];
				temp++;
			}
			
			if(temp>1 && prime[i]>2 ) count*=temp;
			root = sqrt(n);
		}
		if(n>1 && n!=2) count*=2;

		printf("%lld\n",count);
	}
	return 0;
}
Beispiel #11
0
int main()
{
	int	n, *seivearr, i, j, count = 0, limit, maxi = -1, maxv, sum;

	scanf("%d", &n);
	seivearr = seive(n, 0);
	cumulative[count++] = 0;
	for (i = 2; i < n; i++)
		if (!seivearr[i])
			cumulative[count++] = i;
	// Find the cumulative sum of all the primes below one million. At some point the sum will
	// exceed one million. We need not go beyond that point. Fortunately, for this problem the
	// limit sum exceeds a million within the first 600 primes or so
	for (i = 1; i < count; i++)
	{
		cumulative[i] += cumulative[i - 1];
		if (cumulative[i] >= ONE_MILLION)
			break;
	}
	limit = i;
	// The idea now is that the sum of N consecutive primes starting from i is given by
	// cumulative[i + N] - cumulative[i - 1]. Just keep a running count of the max N
	// Since the 'limit' is small (600 or so), the n^2 algorithm runs reasonable fast
	for (i = 1; i < limit; i++)
	{
		for (j = i; j < limit; j++)
		{
			sum = cumulative[j] - cumulative[i - 1];
			assert(sum < ONE_MILLION);
			if (!seivearr[sum])
			{	/* sum is prime */
				if (maxi < (j - i + 1))
				{
					maxi = j - i + 1;
					maxv = sum;
				}
			}
		}
	}
	printf("%d, %d\n", maxi, maxv);
	return 0;
}
Beispiel #12
0
int main()
{
	seive();
	/* for(i=0;i<1000;i++)
	   printf("%d ",prime[i]);
	   */	int m,n,t,i,sq,flag;
	//scanf("%d",&t);
	t=readnum();
	while(t--)
	{
		//scanf("%d%d",&m,&n);
		m=readnum();
		n=readnum();
		if(m<=2)
		{
			printf("2\n");
			m=3;
		}
		else if(m%2==0)
			m=m+1;
		for(i=m;i<=n;i+=2)
		{
			
			flag=0;
			sq=sqrt(i);
			for(j=1;prime[j]<=sq;j++)
			{
				if(i%prime[j]==0)
				{
					flag=1;
					break;
				}
			}
			if(flag==0)
				fastWrite(i);
		}
	}
	return 0;
}
int main()
{long int t,n,q,b,r,i,temp,x;
long long int a,m;
scanf("%ld",&t);
seive();
calc();
while(t--)
{scanf("%ld%llu%ld",&n,&m,&q);
  while(q--)
  {for(i=1;i<=n;i++)
        total[i]=0;
          scanf("%ld",&r);
        b=n-r;
        a=1;
         if((n-r)>r)
            {
               temp=n-r;
               b=r;
               r=temp;
            }
            for(x=2;x<=n;x++)
            {
                total[x]=fact[n][x]-fact[r][x];
            }
            for(x=2;x<=n-r;x++)
                 total[x]=total[x]-fact[n-r][x];
            for(i=2;i<=n;i++)
         {
             if(total[i])
             {
                 a=(a*fastpower(i,total[i],m))%m;
             }
         }
          printf("%llu\n",a);
  }

}
    return 0;
}
Beispiel #14
0
int main()
{
    int n,t,tmp;
    scanf("%d",&t);
    seive();
    for(i=0; i<z; i++)
    {
        for(j=0; j<z; j++)
        {
            tmp=prime[i]+2*prime[j];
            if(tmp<=10000)
                a[tmp]++;
            else
                break;
        }
    }
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",a[n]);
    }
    return 0;
}
Beispiel #15
0
int main() {
    int n, i;
    scanf("%d", &n);
    printf("%d\n", seive(n));
    return 0;
}