Problem Description
source: https://uva.onlinejudge.org/external/119/p11934.html
You are given a quadratic function,
f(x) = ax2 + bx + c
You are also given a divisor d and a limit L. How many of the function values f(0), f(1), . . . , f(L) are divisible by d?
Input
Input consists of a number of test cases. Each test case consists of a single line containing the numbers a b c d L (−1000 ≤ a, b, c ≤ 1000, 1 < d < 1000000, 0 ≤ L < 1000).
Input is terminated by a line containing ‘0 0 0 0 0’ which should not be processed.
Output
Print the answer for each test case (the number of function values f(0), f(1), . . . , f(L) divisible by d) on a separate line.
Sample Input
0 0 10 5 100
0 0 10 6 100
1 2 3 4 5
1 2 3 3 5
0 0 0 0 0
Sample Output
101
0
0
4
source: https://uva.onlinejudge.org/external/119/p11934.html
You are given a quadratic function,
f(x) = ax2 + bx + c
You are also given a divisor d and a limit L. How many of the function values f(0), f(1), . . . , f(L) are divisible by d?
Input
Input consists of a number of test cases. Each test case consists of a single line containing the numbers a b c d L (−1000 ≤ a, b, c ≤ 1000, 1 < d < 1000000, 0 ≤ L < 1000).
Input is terminated by a line containing ‘0 0 0 0 0’ which should not be processed.
Output
Print the answer for each test case (the number of function values f(0), f(1), . . . , f(L) divisible by d) on a separate line.
Sample Input
0 0 10 5 100
0 0 10 6 100
1 2 3 4 5
1 2 3 3 5
0 0 0 0 0
Sample Output
101
0
0
4
Solution:
#include<stdio.h> #include<math.h> int main() { long int n, a,b,c, d, l, count,x; while(scanf("%ld%ld%ld%ld%ld",&a, &b, &c, &d,&l)==5) { if(a==0 && b==0 && c==0 && d==0 && l==0) break; count=0; for(x=0;x<=l;x++) { n=(a*x*x) +(b*x)+c; if(n%d==0) count++; } printf("%ld\n",count); } return 0; }
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience