| ||||||||||
| 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 | |||||||||
Why is it Wrong answer?#include<iostream>
#include<stdio.h>
long num;
long f(long n){
num++;
if(n==1) return num;
else if(n%2==1) return f(3*n+1);
else return f((int)n/2);
}
using namespace std;
int main(){
long i,j;
while(scanf("%d%d",&i,&j)!=EOF&&i>0&&i<10000&&j>0&&j<10000){
if(i>j) swap(i,j);
num=0;
f(i);
long max=num;
for(long k=i+1;k<=j;k++){
num=0;
f(k);
max=max>num? max:num;
}
cout<<i<<' '<<j<<' '<<max<<endl;
}
return 0;
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator