Codesjava
Codesjava
import java.util.*;
Python code
import sys
import heapq
class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = [[0 for column in range(vertices)] for row in range(vertices)]
while pq:
(d, u) = heapq.heappop(pq)
if spset[u]:
continue
spset[u] = True
for v in range(self.V):
if self.graph[u][v] > 0 and not spset[v] and dist[u] != sys.maxsize and dist[u] + self.graph[u][v]
< dist[v]:
dist[v] = dist[u] + self.graph[u][v]
heapq.heappush(pq, (dist[v], v))
if __name__ == "__main__":
V = int(input("Enter nodes: "))
g = Graph(V)
BigInt
import java.math.BigInteger;
import java.util.Scanner;
Python
from decimal import Decimal
def square(a):
stra = str(a)
length = len(stra)
if length == 1:
return a * a
half = length // 2
strb = stra[:half]
strc = stra[half:]
b1 = Decimal(strb)
c1 = Decimal(strc)
b2 = square(b1)
c2 = square(c1)
bc = b1 * c1
pows = Decimal(10) ** (length - half)
result = b2 * (pows * pows) + bc * Decimal(2) * pows + c2
return result
if __name__ == "__main__":
a = Decimal(input("Enter number: "))
rs = square(a)
print("Square is:", rs)