10346 - Peter's Smokes

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

athlon19831
New poster
Posts: 20
Joined: Thu Jan 19, 2006 2:32 pm

10346 WA

Post by athlon19831 » Mon Jan 23, 2006 6:08 pm

please help me

#include "iostream.h"
int main(int argc, char* argv[])
{
long n,k;
long sum;
while(cin>>n>>k)
{
sum=n;
if(k>1)
{
while(n>=k)
{
sum+=n/k;
n=n/k;
}
cout<<sum<<endl;
}
}
return 0;
}

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Sun Feb 05, 2006 9:11 am

If the input is
31 2

The output might be 61
But your output says 57


Becare of the problem:
31/2=15...1
15/2=7....1
7/2=3....1
3/2=1....1
so your output is 31+15+7+1=57
But there are five 1 left!!

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

10346

Post by ishtiaq ahmed » Sun Aug 20, 2006 8:09 am

Actully i dont know why i am facing wrong ans
plz help me.i am a beginner in programmig :cry:
my code is

Code: Select all

#include<stdio.h>
void main()
{
	long long a,b,sum;
	while(scanf("%lld %lld",&a,&b)!=EOF)
	{
		if(b>1)
		{
			sum=a;
			while(a!=0)
			{
				a=a/b;
				sum= sum+a;
			}
			printf("%lld\n",sum);
		}
	}
}
Last edited by ishtiaq ahmed on Wed Feb 07, 2007 1:50 pm, edited 2 times in total.

DP
Learning poster
Posts: 62
Joined: Sun Aug 13, 2006 9:15 am
Location: Bangladesh
Contact:

Post by DP » Sun Aug 20, 2006 8:52 am

You can check this I/O:

Code: Select all

3 2
Output:

Code: Select all

5
1 1 1 =3
---
1 =1
1
----- =1
Total =5

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton » Wed Feb 07, 2007 3:26 pm

delete your code and check the link. you will get more information about peter problem.



http://online-judge.uva.es/board/viewto ... ight=10346






newton... simply the best

User avatar
KaDeG
New poster
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

10346 WA

Post by KaDeG » Fri Apr 13, 2007 7:02 pm

I have made the 10346 problem but got Wa. I searched the forums and found the smart formula: sumciggaret=n+(n-1)/(k-1); I did this and got AC. The problem is with my code, the first idea i had i got WA, the problem testcases works fine and also some other testecase i created from my AC program are OK.
But i still get WA, any ideas why would be helpful...

Code: Select all

#include <stdio.h>

main()  {
        int n, k, sum, nk;
        while((scanf("%d %d", &n, &k))==2)      {
                sum=n;
                nk=sum/k;
                sum+=nk;
                while(nk>=k)    {
                        nk/=k;
                        sum+=nk;
                }
                printf("%d\n", sum);
        }
}
Thanks
/*No Comment*/

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Fri Apr 13, 2007 8:49 pm

Try the cases...

Input:

Code: Select all

8492 142
15881 300
10677 119
Output:

Code: Select all

8552
15934
10767
Hope these help.
Ami ekhono shopno dekhi...
HomePage

User avatar
KaDeG
New poster
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

Post by KaDeG » Fri Apr 13, 2007 10:45 pm

yeah, fixed and got AC
thanks :D
/*No Comment*/

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

Re: 10346 - Peter’s Smokes

Post by asif_khan_ak_07 » Fri Jun 05, 2009 1:49 pm

I wrote the following code and got WA.I tried some test cases and the answers were correct.pls help me to find the mistake

Code: Select all

#include<stdio.h>

int main()
{
long double x,n,ans,r;

while((scanf("%Lf %Lf",&x,&n)==2))
{

if(x<n)
printf("%.0Lf\n",x);

else
{
	
ans=x;

r=x/n;
do
{
ans=ans+r;
r=r/n;

}while(r>=1);

printf("%.0Lf\n",ans);

}

}
return 0;
}

saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 10346 - Peter’s Smokes

Post by saiful_sust » Fri Jun 05, 2009 9:40 pm

Hi asif_khan
Try this case:
INPUT:

Code: Select all

12 3
1200 5
1200 1200
3 2
25326 3652
456987 326596
OUTPUT:

Code: Select all

17
1499
1201
5
25332
456988
[*] IMPOSSIBLE MEANS I M POSSIBLE /[*]

kaysar_buet08
New poster
Posts: 1
Joined: Mon Nov 09, 2009 4:00 pm

Re: 10346 - Peter’s Smokes

Post by kaysar_buet08 » Mon Nov 09, 2009 4:19 pm

where is my error!! :evil:

#include<stdio.h>
int n,a,b;
int main()
{
while((scanf("%d%d",&a,&b))!=EOF)
{
n=a;
while(a>=b)
{
a=a/b;
n+=a;
}
printf("%d\n",n);
}
return 0;
}

khairul
New poster
Posts: 2
Joined: Mon Feb 22, 2010 6:30 pm

Re: 10346 - Peter’s Smokes

Post by khairul » Thu Feb 25, 2010 8:04 am

hi kaysar u must keep rest by modules operator.
suppose,
5 3
output should 7 not 6.
because 5+1+1=5+1+((1+2))/3=7

and also use unsigned int/long.
i think it would work and let me know...
thanks,
khairul

imran_12
New poster
Posts: 9
Joined: Fri Sep 19, 2014 7:56 am

10346- Peter's Smokes

Post by imran_12 » Sat Sep 20, 2014 1:03 pm

I cant understand why i am getting WA..
plz help

Code: Select all

#include<stdio.h>
int main()
{
    int n,k,m,p;
    while(scanf("%d %d",&n,&k)==2)
    {
        m=n;
        if(k>1)
        {
            p=n%k;
            n=n/k;
            p=(p+n)/k;
            m=m+n+p;
        }
        printf("%d\n",m);
    }
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10346- Peter's Smokes

Post by lighted » Sat Sep 20, 2014 1:23 pm

Use search and post in existing thread. http://acm.uva.es/board/search.php?keyw ... f03df06864
Input

Code: Select all

1000 5
Acc Output

Code: Select all

1249
Your Output

Code: Select all

1240
You are doing rolling process one time using if operator. I do it as many as it is possible using loop.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

tomb_raider
New poster
Posts: 2
Joined: Tue Oct 28, 2014 8:42 am

Re: 10346 - Peter's Smokes

Post by tomb_raider » Wed Oct 29, 2014 8:14 pm

Why Wrong ANSWER MANNNNN !?!?!?!?!?!?

Code: Select all

#include <stdio.h>
int main()
{
    long long int a,b,x,y,c,sum1,sum2;
    while(scanf("%lld %lld",&a,&b)==2)
    {
        sum1=0,sum2=0,c=0;
        while(a>0)
        {
            x=a%b;
            sum2=x+sum2;
            if(sum2/b>0)
            {
                c++;
                sum2=sum2/b;
            }
            sum1=sum1+a;
            a=a/b;
        }
        sum1=sum1+c;
        printf("%lld\n",sum1);
    }
    return 0;
}
Last edited by brianfry713 on Wed Oct 29, 2014 9:11 pm, edited 1 time in total.
Reason: Added code blocks

Post Reply

Return to “Volume 103 (10300-10399)”