Question
I need C code for this problem Jamie has n candies. She is willing to share m of them with Mark, where m is the
I need C code for this problem
Jamie has n candies. She is willing to share m of them with Mark, where m is the pth smallest factor of n (i.e., the pth smallest long integer to divide n with no remainder). For example, the factors of n = 8 are (1, 2, 4, 8); if p = 3, then Jamie shares m = 4 candies with Mark.
Complete the function in the editor below. It has two parameters:
Name Type Description
n long integer The number of candies Jamie has.
p long integer Used to determine the pth smallest factor of n.
The function must return a long integer denoting m (i.e., the number of candies Jamie gives Mark). If no pth smallest factor exists, return 0 instead. Input Format The first line contains a long integer denoting n.
The second line contains a long integer denoting p. Constraints 1 < n < 1015
1 < p < 109
Output Format Return a long integer denoting m (i.e., the number of candies Jamie gives Mark). If no pth smallest factor exists, return 0 instead.
Sample Case 0 Sample Input 10 3
Sample Output
5
/* * Complete the function below. */ long int getCandies(long int n, long int p) {
}
int main() { FILE *f = stdout; char *output_path = getenv("OUTPUT_PATH"); if (output_path) { f = fopen(output_path, "w"); }
long int res; long int n; scanf("%ld", &n);
long int p; scanf("%ld", &p);
res = getCandies(n, p); fprintf(f, "%ld ", res);
fclose(f); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started