| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位高人帮忙看一下,过了discuss里的所有数据,就是交上去是WA,不胜感激!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator