Problem Array Checksum 17---Submit answer is wrong but for example input output is correct

Back to General discussions forum

Ivan Vanko     2022-03-03 16:44:53
#include<stdio.h>

int main()
{
    int test,n,i,j,k,sum,arr[1000];
    int seed=113,limit=10000007;
    scanf("%d",&test);
    for(i=0;i<test;i++)
    {
        scanf("%d",&n);
        arr[i]=n;
    }
    sum=0;
    for(j=0;j<test;j++)
    {
        sum=(sum+arr[j])*seed;
        sum=sum%limit;
    }
    printf("\n");
    printf("%d",sum);
    printf("\n");
    return 0;
}

When I give input 6(test) 3 1 4 1 5 9 ouput gives correct answer but submitted answer giving wrong answer

Rodion (admin)     2022-03-03 19:42:53
User avatar

Ivan, Hi!

No need to post your solution, it's visible in your profile :)

Have you seen the very last line in the problem statement? Check if this is causing trouble in your case:

All input values are between 0 and 1,000,000,000 - be sure to take care of possible overflow in progress of calculations!

I.e. make small input with, say, just 3 values 999999998, 999999999, 1000000000 - and check with your code and with pencil

Ivan Vanko     2022-03-03 20:42:06

I understand.Thank you.

Please login and solve 5 problems to be able to post at forum