@lakshayarora7/

WateryVastCoqui

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.09583612720467305","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyMgQ29tcHV0ZSB0aGUgaGlnaGVzdCBjb21tb24gZmFjdG9yIG9mIHR3byBwb3NpdGl2ZSBpbnRlZ2Vycw0KDQojIyBIaWdoZXN0IGNvbW1vbiBmYWN0b3IgaXMgdGhlIGdyZWF0ZXN0IGNvbW1vbiBkaXZpc29yIG9mIHR3byBudW1iZXJzIGUuZy4gMTAgZm9yIDIwICYgMzAsIDUgZm9yIDUgJiAyNSwgMjUgZm9yIDUwICYgNzUNCg0KIyMgVEhPVUdIVCBQUk9DRVNTOiBIQ0Ygd2lsbCBiZSBsZXNzIHRoYW4gb3IgZXF1YWwgdG8gdGhlIHNtYWxsZXIgb2YgdGhlIHR3byBudW1iZXJzIGFuZCBncmVhdGVyIHRoYW4gb3IgZXF1YWwgdG8gMSwgc2luY2UgMSBpcyBhIGZhY3RvciBvZiBldmVyeSBudW1iZXIuIFNvIHdlIGluaXRpYWxpemUgdGhlIEhDRiB2YXJpYWJsZSB0byB0aGUgc21hbGxlciBvZiB0aGUgdHdvLCBhbmQgbG9vcCBiYWNrd2FyZHMgdG8gb25lIGFuZCBhcyBzb29uIGFzIHdlIGZpbmQgYSBudW1iZXIgd2hpY2ggZXZlbmx5IGRpdmlkZXMgdGhlIHR3byBudW1iZXJzLCB3ZSBkZWNsYXJlIGl0IG91ciBoY2YuDQoNCiMjIElOUFVUDQpmaXJzdE51bWJlciA9IGludChpbnB1dCgiRW50ZXIgdGhlIGZpcnN0IG51bWJlcjogIikpDQpzZWNvbmROdW1iZXIgPSBpbnQoaW5wdXQoIkVudGVyIHRoZSBzZWNvbmQgbnVtYmVyOiAiKSkNCg0KIyMgTE9HSUMNCiMgU3RhcnRpbmcgZnJvbSB0aGUgdXBwZXIgbGltaXQgb2YgdGhlIG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hlIGdyZWF0ZXN0IGNvbW1vbiBkaXZpc29yIG9mIiwgZmlyc3ROdW1iZXIsICJhbmQiLCBzZWNvbmROdW1iZXIsICJpcyIsIGhjZikNCg=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Compute the highest common factor of two positive integers

## Highest common factor is the greatest common divisor of two numbers e.g. 10 for 20 & 30, 5 for 5 & 25, 25 for 50 & 75

## THOUGHT PROCESS: HCF will be less than or equal to the smaller of the two numbers and greater than or equal to 1, since 1 is a factor of every number. So we initialize the HCF variable to the smaller of the two, and loop backwards to one and as soon as we find a number which evenly divides the two numbers, we declare it our hcf.

## INPUT
firstNumber = int(input("Enter the first number: "))
secondNumber = int(input("Enter the second number: "))

## LOGIC
# Starting from the upper limit of the highest common divisor i.e. the minimum of the two numbers, check whether it properly divides the two numbers. If not, decrement the number by 1 and repeat the process. As soon as the while loop finds a number which properly divides the two numbers, the current value of hcf variable is the true value of hcf, and it doesn't execute the loop anymore.
## PSEUDO CODE / ALGORITHM: 
# Initialize hcf to the smaller of firstNumber & secondNumber
# While hcf does not evenly divide firstNumber or hcf does not evenly divide secondNumber do 
#     Decrease the value of hcf by 1 
# Report hcf as the greatest common divisor of firstNumber and secondNumber

hcf = min(firstNumber, secondNumber) 
while firstNumber % hcf != 0 or secondNumber % hcf != 0:
    hcf = hcf - 1

## OUTPUTTING CONCLUSION
print("The greatest common divisor of", firstNumber, "and", secondNumber, "is", hcf)