2012-05-17 18:46:37Morris
[UVA] 11703 - sqrt log sin
Problem E: sqrt log sin
An evil professor has just assigned you the following problem.A sequence is defined by the following recurrence:
Determine x1000000.
Input Specification
Input consists of a number of lines, each containing one integer, a value of i, no less than zero and no greater than one million. Input is followed by a single line containing the integer -1. This last line is not a value of i and should not be processed.Sample Input
0 -1
Output Specification
For each value of i in the input (but not the final -1), output the corresponding value of xi modulo 1000000.Output for Sample Input
1
#include <stdio.h>
#include <math.h>
int x[1000001] = {1};
int main() {
int i, a, b, c;
for(i = 1; i <= 1000000; i++) {
a = (int)(i-sqrt(i));
b = (int)log(i);
c = (int)(i*sin(i)*sin(i));
x[i] = (x[a]+x[b]+x[c])%1000000;
}
while(scanf("%d", &i) == 1 && i >= 0)
printf("%d\n", x[i]);
return 0;
}