24h購物| | PChome| 登入
2012-05-17 18:46:37| 人氣915| 回應0 | 上一篇 | 下一篇

[UVA] 11703 - sqrt log sin

推薦 0 收藏 0 轉貼0 訂閱站台

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;
}

台長: Morris
人氣(915) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][組何分配] 10910 - Marks Distribution
此分類上一篇:[UVA][DP最大矩形] 10667 - Largest Block

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文