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

为什么会WA??大虾帮忙~~~~

Posted by ACrun at 2007-01-16 12:14:06 on Problem 2453
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)break;
		int r=1,sum=0,p=n,g=0;
		while(p%2==0)
		{
			p=p/2;r=r*2;g=1;
		}
		while(p%2!=0)
		{
			p=p/2;sum+=r/2;r=r*2;
		}
		sum-=r/4;
		if(g==1)cout<<n+r/2-sum<<endl;
		else cout<<n+r/2<<endl;
	}
	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