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 random | |
def isPrime(num): | |
if num == 2: return True | |
if num < 2 or num % 2 == 0: return False | |
for i in range(3, int(num ** 0.5) + 2, 2): | |
if num % i == 0: return False | |
return True | |
def gcd(e, phi): return e if phi == 0 else gcd(phi, e % phi) |
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
/* | |
Input Format. Input contains one string 𝑆 which consists of big and small latin letters, digits, punctuation | |
marks and brackets from the set []{}(). | |
Constraints. The length of 𝑆 is at least 1 and atmost 10^5. | |
Output Format. If the code in 𝑆 uses brackets correctly, output “Success" (without the quotes). Otherwise, | |
output the 1-based index of the first unmatched closing bracket, and if there are no unmatched closing | |
brackets, output the 1-based index of the first unmatched opening bracket. | |
*/ |
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
/* | |
Dijkstra's Shortest Path Algorithm | |
The following program gives the shortest path from the source to all other nodes | |
*/ | |
import java.util.*; | |
import java.io.*; | |
class DijkstrasAlgorithm{ | |
public static void main(String args[]){ | |
int array[][]; | |
int i,j,n,s; |