371 - Ackermann Functions
Moderator: Board moderators
hello-
when printing:
Between x and y, a generates the longest sequence of b values.
you have to make sure x <= y.
so for input:
20 1
output should be:
Between 1 and 20, 18 generates the longest sequence of 20 values.
and not:
Between 20 and 1, 18 generates the longest sequence of 20 values.
hope it helps.
BTW: other threads already exists about this problem. I assume you are new in this forum... you can search for a particular problem by using the 'search' option. If you don't get the required help, then make a post in that thread.
when printing:
Between x and y, a generates the longest sequence of b values.
you have to make sure x <= y.
so for input:
20 1
output should be:
Between 1 and 20, 18 generates the longest sequence of 20 values.
and not:
Between 20 and 1, 18 generates the longest sequence of 20 values.
hope it helps.
BTW: other threads already exists about this problem. I assume you are new in this forum... you can search for a particular problem by using the 'search' option. If you don't get the required help, then make a post in that thread.
371 why wa
#include<stdio.h>
int main()
{
unsigned long int n,i,count=0,j,k,large=0,w;
do
{
scanf("%lu %lu",&n,&k);
if(n==0&&k==0)
exit(1);
for(j=n;j<=k;j++)
{
i=j;
do
{
if(i%2!=0)
i=3*i+1;
else
i=i/2;
count++;
}while(i!=1);
if(large<count){
w=j;
large=count;
}
count=0;
}
printf("Between %lu and %lu, %lu generates the longest sequence of %lu values.\n",n,k,w,large);
large=0;
}while(n!=0&&k!=0);
return 0;
}
int main()
{
unsigned long int n,i,count=0,j,k,large=0,w;
do
{
scanf("%lu %lu",&n,&k);
if(n==0&&k==0)
exit(1);
for(j=n;j<=k;j++)
{
i=j;
do
{
if(i%2!=0)
i=3*i+1;
else
i=i/2;
count++;
}while(i!=1);
if(large<count){
w=j;
large=count;
}
count=0;
}
printf("Between %lu and %lu, %lu generates the longest sequence of %lu values.\n",n,k,w,large);
large=0;
}while(n!=0&&k!=0);
return 0;
}
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
First number may be greater than Second one in some pair... so consider it..
Just insert This line after scanf()And you will get Accepted.
After getting Accepted, Please dont forget to remove your code.
Keep Posting.
Just insert This line after scanf()
Code: Select all
if(n>k){i=n;n=k;k=i;}
After getting Accepted, Please dont forget to remove your code.
Keep Posting.
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
can anybody help me to do check my code..??
why it can get WA..
thx
why it can get WA..
Code: Select all
deleted after acc..
}
Last edited by albet_januar on Thu Nov 16, 2006 12:17 pm, edited 1 time in total.
Suppose you are told to print 'abc', if you print 'cba' or 'bca' then you will get WA.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
You are not printing correctly. Your code doesnot even pass the sample. Just match both outputs carefully and you will find your error.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
albet_januar wrote:can anybody help me to do check my code..??
why it can get WA..
thxCode: Select all
deleted after ACC..
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
hmm
newton................................ simply the best
Code: Select all
but if it is 00.627 sec?
newton................................ simply the best
371Wa ~~~~ Help ~~~~
#include<stdio.h>
#include<iostream>
using namespace std;
long long int l,h;
long long ark(long long x)
{
unsigned long long a=x;
long long res = 0;
while(a!=1)
{
res++;
if(a%2==0)a/=2;
else a= 3*a+1;
}
return res;
}
int main()
{
while(cin>>l>>h,l!=0 || h!=0)
{
long long i;
if(l>h){i =l;l = h;h= i;}
if(l<=0)break;
long long res = ark(l);
long long resp = l;
long long t;
for(i=l+1;i<=h;i++)
{
t = ark(i);
if(t>res)
{
res = t;
resp = i;
}
}
printf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",l,h,resp,res);
}
return 0;
}
#include<iostream>
using namespace std;
long long int l,h;
long long ark(long long x)
{
unsigned long long a=x;
long long res = 0;
while(a!=1)
{
res++;
if(a%2==0)a/=2;
else a= 3*a+1;
}
return res;
}
int main()
{
while(cin>>l>>h,l!=0 || h!=0)
{
long long i;
if(l>h){i =l;l = h;h= i;}
if(l<=0)break;
long long res = ark(l);
long long resp = l;
long long t;
for(i=l+1;i<=h;i++)
{
t = ark(i);
if(t>res)
{
res = t;
resp = i;
}
}
printf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",l,h,resp,res);
}
return 0;
}
Don't create a new thread if there is one already..
Use this one..
http://online-judge.uva.es/board/viewtopic.php?t=2814
Use this one..
http://online-judge.uva.es/board/viewtopic.php?t=2814
information On 371
1.when n =1,the value is 3,not 1.....
2.the input and output is in the range of long,but the sequence may out of it.
2.the input and output is in the range of long,but the sequence may out of it.