Search found 5 matches

by mps
Thu Jan 06, 2011 9:54 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 320456

Re: If you get WA in problem 100, read me before post!

found the bug.. i was trying to access arr where i was more than 1000001 (max size defined). Put a check to see if i is less than the arr size and then try to access it.


unsigned int comp(unsigned int z)
{
if(z<=1000001)
{
if (arr[z]==0)
{
if (z%2==0)
arr[z] = comp(z/2)+1;
else
arr[z ...
by mps
Thu Jan 06, 2011 9:53 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 320456

Re: Runtime Error 3n+1 Problem

found the bug.. i was trying to access arr where i was more than 1000001 (max size defined). Put a check to see if i is less than the arr size and then try to access it.


unsigned int comp(unsigned int z)
{
if(z<=1000001)
{
if (arr[z]==0)
{
if (z%2==0)
arr[z] = comp(z/2)+1;
else
arr[z ...
by mps
Thu Jan 06, 2011 5:08 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 320456

Runtime Error 3n+1 Problem

Greetings..

Can someone please help me point out whats causing the Runtime error in the below code?


#include <iostream>
using namespace std;
unsigned int arr[1000001];
unsigned int comp(unsigned int z)
{
unsigned int y;
if (arr[z]==0)
{
if (z%2==0)
y=z/2;
else
y=(3*z)+1;
arr[z] = comp(y ...
by mps
Thu Jan 06, 2011 12:37 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 320456

Re: If you get WA in problem 100, read me before post!

greetings..
can anyone please help me with the below piece of code? am getting runtime error

#include <iostream>
using namespace std;
unsigned int arr[1000001];
unsigned int comp(unsigned int z)
{
unsigned int y;
if (arr[z]==0)
{
if (z%2==0)
y=z/2;
else
y=(3*z)+1;
arr[z] = comp(y)+1 ...
by mps
Thu Aug 28, 2008 11:55 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 320456

Re: If you get WA in problem 100, read me before post!

My Code:


#include <iostream>
#include<iomanip>
using namespace std;
int main(int argc,char *argv[])
{
long int i=0,j=0;
while(scanf("%ld %ld",&i,&j)
!=EOF)
{
// cin>>i>>j;
// scanf("%ld",&i);
// scanf("%ld",&j);
cout<<i<<" "<<j<<" ";
if(i>j)
{long int x;
x=i;
i=j;
j=x;}
int *flag= new ...

Go to advanced search