10093 - An Easy Problem!
Moderator: Board moderators
-
- New poster
- Posts: 1
- Joined: Wed Apr 24, 2013 12:10 pm
Re: 10093 - An Easy Problem!
i want to know that why do i need to sum the digits of given integer ???? and it is related to its minimum base value!!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10093 - An Easy Problem!
Check input and AC output for thousands of problems on uDebug!
Re: 10093 - An Easy Problem!
I used algorithm as it is said here. But I got WA. . . . help me please!
http://ideone.com/Q7gFyx
Here is my codes. . . .
http://ideone.com/Q7gFyx
Here is my codes. . . .
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10093 - An Easy Problem!
Check input and AC output for thousands of problems on uDebug!
Re: 10093 - An Easy Problem!
Thanks! I got AC. . . ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- New poster
- Posts: 32
- Joined: Fri Oct 10, 2014 1:10 pm
- Location: Sylhet, Bangladesh
Re: 10093 - An Easy Problem!
INPUT
OUTPUT of my code
AC OUTPUT
i think 2727 is an octal number(minimum base)..
but AC code says it is decimal..why???
Code: Select all
265
2727
Code: Select all
7
8
Code: Select all
14
10
but AC code says it is decimal..why???
None but a fool is always right..
so don't be upset when u r wrong..
so don't be upset when u r wrong..
Re: 10093 - An Easy Problem!
Answer for 2727 is N = 10. Because according problem description given input number R is divisible by (N - 1). If N = 8 then 7*1 + 2*8 + 7*64 + 2*512 = 1495. 1495 is not divisible by (8 - 1 = 7). So N = 8 is wrong answer.You will be given an N based integer number R and you are given the guaranty that R is divisible by (N-1). You will have to print the smallest possible value for N
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
10093
this code shows WA...can you please help me finding the mistake?Thanks in advance
Code: Select all
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int digit(char *n, int i)
{
//negative sign
if (n[i] == '-' || n[i] == '+' || n[i] == ' ')
return 0;
// 0 to 9
if (n[i] >= '0' && n[i] <= '9')
return (n[i] - '0');
// A to Z for 32 base
if (n[i] >= 'A' && n[i] <= 'Z')
return 10 + (n[i] - 'A');
// a to z for 62 base
if (n[i] >= 'a' && n[i] <= 'z')
return 36 + (n[i] - 'a');
return 0;
}
bool isDivisible(char *n, int bMinusOne)
{
int sumOfDigits = 0;
for (register int i=0; i<strlen(n) ; i++)
sumOfDigits += digit(n,i);
return !(sumOfDigits%bMinusOne);
}
int main()
{
char R[1000];
int N = 63;
while ( scanf ("%s", R) == 1 ) {
// first we need to deetermine minimum base that is valid
// so determing latgest digit will pave the way
int maxDigit = 0;
for (register int i=0; i<strlen(R) ; i++)
maxDigit = max(digit(R,i),maxDigit);
//handling 0 because isDivisble function will divide n by 0!
if (maxDigit == 0)
{
cout << "such number is impossible!" << endl;
continue;
}
//minimum base is maxDigit + 1
for (int b=maxDigit+1; b<=62; b++)
{
if (isDivisible(R,b-1)){
N = min(N,b);
}
}
if (N == 63){
printf ("such number is impossible!\n");
} else {
printf ("%d\n",N);
}
N = 63;
}
return 0;
}