ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1083. Factorials!!!

Runtime error(access violation)
Posted by Mithun Saha 20 Jul 2017 22:24
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    long int n,k,val,fact=1,coeff=0;

    char ch[24],*num,*excl;

    gets(ch);

    num=strtok(ch," ");
    n=atoi(num);

    excl=strtok(NULL,NULL);
    k=strlen(excl);

    while(coeff*k<n)
    {
        val=n-coeff*k;
        fact=fact*val;
        coeff++;
    }


    if(n%k!=0)
        fact=fact*(n%k);
    else fact=fact*k;

    printf("%ld",fact);

    return 0;
}


Hi! I am getting runtime error(access violation) although the solution seems to work for different set of inputs. Please help me out!
Re: Runtime error(access violation)
Posted by Mahilewets 21 Jul 2017 00:27
http://ideone.com/1tNjl7
I have corrected your solution.
Even if fix Access violation,
You are just WA#5
(Because of a logic error)

Edited by author 21.07.2017 00:59
Re: Runtime error(access violation)
Posted by Mithun Saha 23 Jul 2017 20:07
Hi Mahilewets! Thanks a lot! I did correct the "Runtime error" but was getting a "Wrong answer" error due to the error in logic in the while condition. Your's is the right one.
Just a query though(pardon my ignorance as I am new to this kind of stuff). How do you find the test cases for each problem apart from the one already given?
Re: Runtime error(access violation)
Posted by Mahilewets 23 Jul 2017 21:57