| ||||||||||
| 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 | |||||||||
Re:我的RE疯了,那位高手帮忙看看?附代码In Reply To:我的RE疯了,那位高手帮忙看看?附代码 Posted by:liweishun2269 at 2008-05-31 16:10:37 > #include<iostream>
> #define M 1000000000
> using namespace std;
> int main()
> {
> int i,j,n;
> bool pr[M];
> double sum;
> for(i=0;i<M;i++)pr[i]=1;
> for(i=2;i*i<=M;i++)
> {
> if(pr[i-1])
> {
> for(j=i*i;j<=M;j+=i)pr[j-1]=0;
> }
> }
> while(1)
> {
> cin>>n;
> if(n==0)return 0;
> sum=n;
> for(i=2;i<=n/2;i++)
> {
> if(!pr[i-1])continue;
> if(n%i==0)sum*=1-1.0/i;
> }
> if(pr[n-1])sum*=1-1.0/n;
> cout<<sum<<endl;
> }
> }
for(j=i*i;j<=M;j+=i)pr[j-1]=0;
应该是j=2*i吧?
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator