Skip to content

Commit 25ddc4e

Browse files
added maths codes
1 parent ca9b201 commit 25ddc4e

File tree

8 files changed

+84
-19
lines changed

8 files changed

+84
-19
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Scanner;
2+
import java.math.BigInteger;
3+
public class gcdBigInteger{
4+
public static void main(String[] args)/*throws IOException*/{
5+
/*final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6+
BigInteger a=new BigInteger(br.readLine());
7+
BigInteger b=new BigInteger(br.readLine());
8+
*/
9+
final Scanner cin=new Scanner(System.in);
10+
BigInteger a=cin.nextBigInteger();
11+
BigInteger b=cin.nextBigInteger();
12+
System.out.println(a.gcd(b));
13+
}
14+
}
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Scanner;
2+
import java.math.BigInteger;
3+
public class gcdBigInteger{
4+
public static void main(String[] args)/*throws IOException*/{
5+
/*final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6+
BigInteger a=new BigInteger(br.readLine());
7+
BigInteger b=new BigInteger(br.readLine());
8+
*/
9+
final Scanner cin=new Scanner(System.in);
10+
BigInteger a=cin.nextBigInteger();
11+
BigInteger b=cin.nextBigInteger();
12+
System.out.println(a.gcd(b));
13+
}
14+
}

practice/maths/GcdLcm.class

1.11 KB
Binary file not shown.

practice/maths/GcdLcm.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//a*b=lcm*gcd
2+
import java.util.Scanner;
3+
import java.math.*;
4+
public class GcdLcm{
5+
public static void main(String[] args){
6+
final Scanner cin = new Scanner(System.in);
7+
int testCase=cin.nextInt();
8+
for(int i=0;i<testCase;i++){
9+
long a=cin.nextLong();
10+
long b=cin.nextLong();
11+
long gcd=findGcd(Math.max(a,b),Math.min(a,b));
12+
long lcm=getLcm(gcd,a,b);
13+
System.out.println(lcm+" "+gcd);
14+
}
15+
}
16+
private static long findGcd(long a,long b){
17+
if(b==0){
18+
return a;
19+
}
20+
return findGcd(b,a%b);
21+
}
22+
private static long getLcm(long gcd,long a,long b){
23+
return ((a*b)/gcd);
24+
}
25+
}
26+

spoj/2q

Lines changed: 0 additions & 19 deletions
This file was deleted.

spoj/factorialTrailingZero.class

1.36 KB
Binary file not shown.

spoj/factorialTrailingZero.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.*;
2+
import java.math.*;
3+
public class factorialTrailingZero{
4+
public static void main(String[] args)throws IOException{
5+
final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6+
int t=Integer.parseInt(br.readLine());
7+
for(int i=0;i<t;i++){
8+
System.out.println(trailingZeroes(Integer.parseInt(br.readLine())));
9+
}
10+
}
11+
private static int factorial(int n){
12+
BigInteger fact=BigInteger.ONE;
13+
for(int i=2;i<=n;i++){
14+
fact=fact.multiply(BigInteger.valueOf(i));
15+
}
16+
int count=0;
17+
while(fact.mod(BigInteger.TEN)==BigInteger.ZERO){
18+
++count;
19+
fact=fact.divide(BigInteger.TEN);
20+
}
21+
return count;
22+
}
23+
public static int trailingZeroes(int A) {
24+
int count=0;
25+
for(int i=5;(A/i)>0;i=i*5){
26+
count+=A/i;
27+
}
28+
return count;
29+
}
30+
}

0 commit comments

Comments
 (0)