首页 > 用户发贴区 > 编程问题提问区 > 好汉,救命!!
2008
11-08

这是很简单的一道递归函数题,


不知哪位好汉帮帮忙,我C语言学的很差,


顺便想问一下怎样学好它,谢谢!!!


还有为什么有人说它很简单,我却感觉很难呢?


我不敢奢望有学C语言的诀窍,但是我真的很希望


知道有没有办法让它简单点,很无奈,


WHO CAN  HELP ME???


Recursive Function


——————————————————————————–


Time limit: 1sec. Submitted: 1499
Memory limit: 32M Accepted: 345


Source : SCU Programming Contest 2005 Preliminary


——————————————————————————–


Function f(n) is recursively defined as:


f(n) = f(n-1) + f(n-3), n > 3
f(n) = n, n <= 3
Write a program to calculate f(n) modulo m.


n <= 10000, 2 <= m <= 10000.


Input


There are multiple test cases. Each test case consists of two integers: n and m. n = 0 and m = 0 denotes the end of input, and you should not process this case.


Output


For each test case, print f(n) modulo m in a single line.


Sample Input


1 2
10000 999
0 0
Sample Output


1
433


——————————————————————————–
Author: wiltord
——————————————————————————–
 撇嘴HELP!!!!


好汉,救命!!》有 1 条评论

  1. yrqtl 说:

    可能是我学C语言不够深,感觉这个好像不是C语言。

留下一个回复