Problem : CodeChef: Practical coding for everyone
My Solution : CodeChef: Practical coding for everyone
Working well with most of my Testcases ; Please help !
Problem : CodeChef: Practical coding for everyone
My Solution : CodeChef: Practical coding for everyone
Working well with most of my Testcases ; Please help !
It does not work for the following simple test case:
1
5 2
1 1 3 3 8
Your code generates 3, while it should be 4.
The code has multitude of problems, starting with
int n,k;
char numbers[n+1];
int sum=0,sum1=0,prod=1,fprod=1,res=0,p;
cin>>n>>k;
for(int i=0;i<n;i++){
int num=1;
cin>>p;
for(int j=0;j<p;j++) {
num=num*k;
}
numbers[i]=num;
}
What’s the most interesting is that your code is still able to solve some of the test cases.
@oleg_b Thank You ! Even ‘long long int’ won’t work for storing the values of the (integer)^(power) , Please correct me if I am wrong ?
Yes, ‘long long int’ does not have sufficient capacity. The approach should be quite different - you need to represent the numbers in the base of k. For example, if k is 10, then 10^100 is a vector with 101 elements, all of them are zeros, except the last one which is 1.