Beebot-big data problem, beebot-Big Data
Source code:
1 # include <stdio. h> 2 3 unsigned long RoadWay (int n) {// defines the unsigned long type 4 unsigned long num1 = 1lu, num2 = 2lu; 5 unsigned long temp; 6 int I; 7 if (n = 2) {8 return 1lu; 9} else if (n = 3) {10 return 2lu; 11} else {12 for (I = 4; I <= n; ++ I) {13 temp = num1 + num2; 14 num1 = num2; 15 num2 = temp; 16} 17 return num2; 18} 19} 20 21 int main (int argc, const char * argv []) {22 // insert code here... 23 int n; 24 int a, B; 25 int len; 26 27 scanf ("% d", & n); 28 29 while (n> 0) {30 scanf ("% d", & a, & B); 31 if (a> 0 & a <B & B <50) {32 len = B-a; 33 printf ("% I64d \ n", RoadWay (1 + len); 34} else {35 break; 36} 37 -- n; 38} 39 40 return 0; 41}
Summary:
- Do not use recursive algorithms as much as possible. You can use loop or tail recursion.
- Int-> unsigned int = unsigned long-> unsigned long