## 10696 - f91

Moderator: Board moderators

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

### 10696 - f91

i get WA for this problem.

for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans

any test cases ?????

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Contact:
Your idea is alright. Check your output format and you need long for this problem.

Zaspire
New poster
Posts: 36
Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia

### Why my program use so many memory?

Why my program use 440 memory?(10696)

#include <iostream>

int main()
{
int n,k;
std::cin>>n;
while (n!=0)
{
if (n<=100) k=91;
else k=n-10;
std::cout<<"f91("<<n<<") = "<<k<<std::endl;
std::cin>>n;
}
return 0;
}

Deny Sutani
New poster
Posts: 6
Joined: Fri Jun 01, 2007 7:20 am

### Re: Why my program use so many memory?

Zaspire wrote:Why my program use 440 memory?(10696)

#include <iostream>

int main()
{
int n,k;
std::cin>>n;
while (n!=0)
{
if (n<=100) std::cout<<"f91("<<n<<") = "<<91<<std::endl;
else std::cout<<"f91("<<n<<") = "<<n-10<<std::endl;
std::cin>>n;
}
return 0;
}
Maybe that one will be better. My code only use 396, but still not good at all

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:
Probably an error in the memory calculation, you can pay no attention to it if you get AC.

I remember a few years back the memory calculation are just totally off for some problems, I can allocate a 2M int array and it says I use 64KB....

But I think they've fixed a lot of those already and most are accurate. Still, can have bugs here.

ahmed
New poster
Posts: 9
Joined: Tue Mar 17, 2009 6:36 pm

### Re: 10696 - f91

Code: Select all

``````#include<iostream>

using namespace std;

int f91(int n)
{
if(n<=100)
{
return f91(f91(n+11));
}
else if(n>=101)
return n-10;
}

int main(void)
{
int n;
while(cin>>n)
{
if(n==0)
return 0;
cout<<"f91("<<n<<") = "<<f91(n)<<endl;
}
return 0;
}
``````

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: 10696 - f91

Replace the input/output by scanf and printf
you can directly use this for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans by an if. No need for this f91 function.
try_try_try_try_&&&_try@try.com
This may be the address of success.

wasifhossain
New poster
Posts: 3
Joined: Tue Apr 28, 2009 7:26 pm

### Re: 10696 - f91

Code: Select all

``````#include<iostream>

using namespace std;

int f91(int n)
{
if(n<=100)
{
return f91(f91(n+11));
}
else if(n>=101)
return n-10;
}

int main(void)
{
int n;
while(cin>>n)
{
if(n==0)
return 0;
cout<<"f91("<<n<<") = "<<f91(n)<<endl;
}
return 0;
}
``````
Yours One is a Naive Straight-forward approach. Try to find the TRICK inside the recursive case by simulating some small cases(N <= 100) using your existing solution above. You'll find a simple number again & again! Now the rest is left upon you. Enjoy!

Enayet Kabir
New poster
Posts: 7
Joined: Mon Jun 04, 2012 3:03 pm

### UVA Problem ID :10696(Why I am getting Presentation error?)

Here is my source code:
=========================
#include<stdio.h>
long N,result;
long int Mc(long int );
int main()
{

while(scanf("%ld",&N)==1)
{
if(N==0) break;
else
{
result=Mc(N);
printf("f91(%ld) = %ld\n",N,result);
}
}
return 0;
}

long Mc(long int N)
{
if(N>=101)
return (N-10);
else
return (Mc(Mc(N+11)));
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: UVA Problem ID :10696(Why I am getting Presentation erro

That is AC code.
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

### Re: 10696 - f91

Hello
I've got WA, Why?

Here is my solution

Code: Select all

``````AC
``````
Last edited by sith on Wed Jun 27, 2012 8:13 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10696 - f91

Don't print the runtime at the end.
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

### Re: 10696 - f91

Thanks, my stupid mistake

raihan_sust5
New poster
Posts: 6
Joined: Tue Jul 23, 2013 3:04 am

### Re: 10696 - f91

i didn't get that how caluculate the f91 for N<= 100......anyone help please..

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10696 - f91

If N <= 100 then f91(N) = 91.
Check input and AC output for thousands of problems on uDebug!