## 10346 - Peter's Smokes

Moderator: Board moderators

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

### 10346 WA

#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
If the input is
31 2

The output might be 61

Becare of the problem:
31/2=15...1
15/2=7....1
7/2=3....1
3/2=1....1
But there are five 1 left!!

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am

### 10346

Actully i dont know why i am facing wrong ans
plz help me.i am a beginner in programmig
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
Contact:
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

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Contact:

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

newton... simply the best

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

### 10346 WA

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
Contact:
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

New poster
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm
yeah, fixed and got AC
thanks
/*No Comment*/

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

### Re: 10346 - Peter’s Smokes

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

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

where is my error!!

#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

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

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: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10346- Peter's Smokes

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``

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

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.