Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位高人帮忙看一下,过了discuss里的所有数据,就是交上去是WA,不胜感激!

Posted by lxhgww at 2006-07-19 22:02:37 on Problem 2773
#include<stdio.h>
#include<string.h>
int main()
{
 long j,i,m,ou,n,k;
 long a[500000],l;
 bool b[1000001];
 l=0;
 n=1000;
 memset(b,true,sizeof(b));
 for (i=2;i<=1000000;i++)
	if (b[i])
	{
	 for (j=i;j<=1000000/i;j++)
	   b[j*i]=false;
	 l++;
	 a[l]=i;
	}
 while (scanf("%ld%ld",&m,&k)!=EOF)
 {
  memset(b,true,sizeof(b));
  ou=m;
  for (i=1;i<=l;i++)
  {
    if (m%a[i]==0) 
	{
	 ou=ou*(a[i]-1)/a[i];
	 for (j=1;j<=m/a[i];j++)
	   b[j*a[i]]=false;
	}
	if (m<a[i]) break;
  }
  n=k/ou;
  j=k%ou;
  if (j==0) 
	if (m==1) printf("%lld\n",k);
	  else printf("%lld\n",m*n-1); 
  else
	{
     i=1;
     while(1)
	 {
      if (b[i]) j--;
      if (j==0) break;
      i++;
	 }
     printf("%lld\n",m*n+i);
	}
 }
 return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator