| ||||||||||
| 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 | |||||||||
Problem 1207I am trying the following code and it returns correct data running through visual studio express 2008 but it gives me wrong answer in this site. I am assuming that it has something to do with how I am reading in my numbers. Does anyone know why
#include <iostream>
#include "stdafx.h"
using namespace std;
int main()
{
int i, j, v, count=0, max=0;
cin >> i >> j;
for (int n=i; n<=j; n++)
{
v=n;
if (v==1)
{
count++;
}
else
{
do{
if (v % 2== 0)
{
v=v/2;
count++;
}
else
{
v=3*v+1;
count++;
}
}while (v!=1);
}
if (count > max)
{
max=count;
}
}
cout << i << " " << j << " " << max << "\n";
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator