Last active
November 26, 2015 14:29
-
-
Save Michal-Szczepaniak/152b67bcac3f28b277f5 to your computer and use it in GitHub Desktop.
silnia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.math.BigInteger; | |
import java.io.PrintWriter; | |
import java.io.File; | |
public class Hello{ | |
public static BigInteger n,sum,i,d; | |
public static int cores; | |
static class MyThread implements Runnable { | |
BigInteger g,n; | |
public MyThread(BigInteger g, BigInteger n) { | |
this.g = g; | |
this.n = n; | |
} | |
public void run() { | |
BigInteger temp = g; | |
for(int i = 0; g.compareTo(n.subtract(BigInteger.valueOf(1)))==-1; g = g.add(BigInteger.valueOf(1))) { | |
temp = temp.multiply(n.add(BigInteger.valueOf(1))); | |
} | |
Hello.sum = Hello.sum.multiply(temp); | |
System.out.print("a\n"); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
Scanner scan = new Scanner(System.in); | |
System.out.print("Podaj liczbe watkow: "); | |
cores = Integer.parseInt(scan.next()); | |
Thread[] threads = new Thread[cores]; | |
System.out.print("Podaj liczbe: "); | |
File plik = new File("liczba.txt"); | |
plik.createNewFile(); | |
PrintWriter zapis = new PrintWriter("liczba.txt"); | |
n = new BigInteger(scan.next()); | |
sum = BigInteger.valueOf(1); | |
i = BigInteger.valueOf(1); | |
d = n.divide(BigInteger.valueOf(cores)); | |
int z = 0; | |
System.out.print(n.toString() + " " + i.toString() + "\n"); | |
while(i.compareTo(n)==-1) { | |
Runnable temp = new MyThread(i, i.add(d)); | |
threads[z] = new Thread(temp); | |
threads[z].start(); | |
i = i.add(d); | |
z++; | |
} | |
System.out.print("poczekaj aż wyswietli sie a w liczbie watkow i wpisz cokolwiek: "); | |
scan.next(); | |
System.out.print("Zapisywanie do pliku: "); | |
zapis.print(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment