Math and Watermelons

Your friend has M watermelons. He doesn’t want to share them with anyone, but let’s imagine he would…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

can’t understand where is my problem :frowning:

M = int(input())
K = int(input())
a = M / K
b = int(a)
c = b * K
d = M - c
print(d)

worked in other python3 ide,but not working in here :frowning: answer is also correct but saying runtime error :frowning:

The way you are taking inputs is incorrect.
Learn about map
try,

N, M = map(int, input().split())
1 Like
water_melons=int(input())
mens=int(input())
c=int(water_melons/mens)
d=int(c*mens)
e=water_melons-d
print(e)	

my output is always correct but all time tells runtime error

@Bonkim The answer to your question is right in the post above your one:

Why are you doing this when you solve this problem in 2 line code like this:

m,k=map(int,input().split())
print(m%k)
#include<Stdio.h>
int main()
{
    int M,K,a;
    scanf("%d %d",&M,&K);
    a=M%K;
    printf("%d",a);

    return 0;
}

where was the problem , compile error

@Rifat.or Share your code link please!

package toph;

import java.util.Scanner;

/**
 *
 * @author Md Rifat
 */
public class MathandWatermelons {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int M,K,a;
        M=in.nextInt();
        K=in.nextInt();
        a=M%K;
        System.out.println(a);
    }
}

runtime error. How can I solve this problem

I know why you got RE.
There is problem to your code with taking input.
You should take input as:
M k
Not

M
K

In python some people do mistake as they take input as:

M = int(input())
K = int(input())

But they should do this to get AC:

M,K = map(int,input().split())

in java how can i input multiple values in one line . if you know that please tell me . thank you

@Rifat.or I think that will help.

String input = scanner.nextLine();    // get the entire line after the prompt 
String[] numbers = input.split(" "); // split by spaces

P S : I don’t know java well. You can search google.

i can’t find anything form google

//correct your spelling , <stdio.h>
//please follow me on instagram.
//instagram.com/saque_lain

#include <stdio.h>
int main() {

int x, y;
scanf("%d %d", &x, &y);
printf("%d", x%y);

return 0;

}

This is simplest solution and it worked.
#include
using namespace std;
int main() {
int water;
int people;
cin>> water >> people;
int res = water % people;

cout<<res;
return 0;

}

Your solution’s great. But…

The reason is, your code will actually be a spoiler for other solvers.

Thanks for understanding!