周宝贝周宝贝吧 关注:5贴子:281
  • 2回复贴,共1

problem 7 Fibonacci Numbers

只看楼主收藏回复

Problem statement
Fibonacci numbers are defined by the function f where f(0) = 0; f(1) = 1; and f(n) = f(n - 1) + f(n - 2).The sequence goes 0, 1, 1, 2, 3, 5, 8, . . .
Lucas numbers are very similar and are defined by the function f where f(0) = 2; f(1) = 1; and f(n) = f(n - 1) + f(n - 2).The sequence goes 2, 1, 3, 4, 7, 11, 18, 29, . . .
There are many, many relationships between these two sequences.Write a program to calculate and print the nth Lucas number modulo m.Specifically, you need to consider some very, very large values for n and relatively small values for m.
Input
The input file will contain many test cases. Each test case consists of one line containing two integers n and m. Both are positive and small enough to fit inside a 64-bit unsigned type. Handle every line.
Output
For each set of test values n and , print the nth Lucas number modulo m. as shown below. At the end, your program must print your family name in Pinyin, your personal name in Pinyin, your full name in Simplified Chinese, and your NUPT ID number EXACTLY in that order. Print the required information on one line by itself. Separate the elements by a single semicolon (no spaces) exactly as shown in the sample output.(This shows that all input has been processed and no errors have occurred.)
Sample Input
1 2
2 1
2 4
4 2
3 8
8 3
4 16
16 4
Sample Output
1
0
3
1
4
2
7
3
Wang;Haojie;王皓杰;H10000708
NOTE CAREFULLY: Pay close attention to spaces and punctuation. Your program must produce exactly the required output (nothing extra) and DETAILS COUNT. The sample input and output are often suggestive. Your program will likely be tested with DIFFERENT data.)


1楼2015-11-05 14:44回复
    import java.util.Scanner;
    class e
    {
    public static void main(String[] args)
    {
    Scanner x = new Scanner(System.in);
    int numbers = x.nextInt();
    int i = 0;
    int j = 0;
    int p = 0;
    char[] c = new char[]{'L','O','M','I','G','H'};
    int[] num = new int[]{1250,250,50,25,5,1};
    for(i = 0;i < numbers;i++)
    {
    p = x.nextInt();
    for(j = 0;j < 6;j++)
    {
    dig(p,num[j],c[j]);
    p = p % num[j];
    }
    System.out.printf("\n");
    }
    }
    static void dig(int a,int b,char p);
    {
    while(a/b>0)
    {
    a = a - b;
    System.out.printf("%c",p);
    }
    }


    2楼2015-11-07 14:58
    回复
      2025-09-17 23:11:47
      广告
      不感兴趣
      开通SVIP免广告
      import java.util.Scanner;
      import java.to.*;
      public class e
      {
      public static void main(String[] args)
      {
      try
      {
      Scanner in = new Scanner(new File("_E.in");
      while(in.hasNextline())
      {
      String c = in.nextline();
      System.out.println(c);
      }
      }
      catch(FileNotFoundException e)
      {
      e.printStackTrace();
      }
      }
      }


      3楼2015-11-11 23:01
      回复