Advertisement
Guest User

Fibonacci Divisibility

a guest
Nov 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Fibonacci_Divisibility
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] lines = System.IO.File.ReadAllLines(@"Input.txt");
  11.             var numbers = lines[1].Split(' ').Select(Int32.Parse).ToArray();
  12.  
  13.             string cuccli = "";
  14.  
  15.             foreach (int num in numbers)
  16.             {
  17.                 int i = 1;
  18.                 while (FibonacciIteravite(i) % num != 0)
  19.                 {
  20.                     i++;
  21.                 }
  22.                 cuccli += i.ToString();
  23.             }
  24.  
  25.             Console.ReadKey();
  26.         }
  27.  
  28.         static System.Numerics.BigInteger FibonacciIteravite(int n)
  29.         {
  30.             System.Numerics.BigInteger current = 1;
  31.             System.Numerics.BigInteger previous = 0;
  32.  
  33.             for (int i = 1; i <= (n - 1); i++)
  34.             {
  35.                 System.Numerics.BigInteger temp = current + previous;
  36.                 previous = current;
  37.                 current = temp;
  38.             }
  39.  
  40.             return current;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement