Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Toolkit;
- import java.awt.datatransfer.StringSelection;
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- //String s1 = "656006096262142989350178033729549556642676383232336265433784409742154433804661332137484567136571199328212724757371571537299468910158925926520634267410117568569929788383355349652486489818108622969402477887141685962903374297020809706805196713227956014251877900218898169451536868965760698964216982448169886501238156520802621307753044482574180109648240541866529324983414010189670221762155494932626210505";
- //String s2 = "250572031945003272238062679321828252833825213808823514984330268366978962197341129230519532039014797883605808330899720778605308114380839942796889389428927605299078556674667262716674388794375852673649320630692741493085455843731600778404958287462585565120043104898780253688088872688246379722105843535447234778633004665956274642418148252674366749520021561386892682686265905694179065413231025238392035696";
- //System.out.println(skipStep(s1, s2));
- //System.out.println(addBig(s1, s2));
- Scanner sc = new Scanner(System.in);
- while(true){
- StringSelection ss = new StringSelection(calcFormatted(Integer.parseInt(sc.nextLine())));
- Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
- }
- }
- public static BigInteger addBig(String number1, String number2){
- BigInteger num1 = new BigInteger(number1), num2 = new BigInteger(number2);
- return num1.add(num2);
- }
- public static BigInteger skipStep(String number1, String number2){
- BigInteger num1 = new BigInteger(number1), num2 = new BigInteger(number2);
- BigInteger firstStep = num1.add(num2);
- return firstStep.add(num1.max(num2)); //This skips a step in the Fibonacci sequence, by adding the bigger number twice.
- }
- public static BigInteger calc(int num){
- BigInteger num1 = new BigInteger("1"), num2 = new BigInteger("2");
- for (int x = 3; x < num; x++){
- num1 = num1.add(num2);
- x++;
- if (x == num){
- return num1;
- }
- num2 = num2.add(num1);
- }
- return num2;
- } //1 1 2 3 5 8 13 21 34
- public static String calcFormatted(int num){
- return "F(" + num + ") =\n\n" + calc(num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement