Hello, Hello, my name is Dream ah , An interesting Python Blogger , Please go easy on me
2021 Blog star of the year TOP100,2021 Blog star of the year TOP5,Python Quality creators in the field , Welcome to cooperate with me ( At the end of the article VX Want to join the learning exchange group or Learning materials welcome +++)Introductory notes : This paradise never lacks genius , Hard work is your final ticket !
Last , May we all shine where we can't see , Let's make progress together
“ Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place ”, It's me ! Ha ha ha ~
Preface :
【Python Training camp 】 Is aimed at Python A war created by language learning Brush questions and revel party! If you don't grasp the solid foundation of knowledge , Welcome to this course :Python Public class It's best to use it together ~ If you like, hurry up and subscribe ! If you don't have self-control or motivation to learn and communicate together , Welcome to send a private letter or add my... At the end of the text VX, I will pull you into the learning exchange group , Let's exchange and study together , Group punch in
Title Description
This question is to fill in the blanks , Just calculate the result , Use the output statement in the code to output the filled results .
If the greatest common divisor of the numerator and denominator of a fraction is 1, This fraction is called a reduced fraction .
Excuse me, , How many committed scores are there , The numerator and denominator are 1 To 2020 Integer between ( Include 1 and 2020)?
Operation limit
Maximum operation time :2s
Maximum running memory : 128M
math.gcd(int1,int2)
# Time : 2022/2/15 13:07
# File : reduced fraction .py
# Author : yes Dream ah !
# VX : Xu18300396393
# Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place !
import math
count = 0
for i in range(1,2021):
for j in range(1,2021):
if math.gcd(i,j) == 1:
count += 1
print(count)
1. greatest common divisor greatest common divisor
import math
# Find the greatest common divisor of these two integers
print (math.gcd(3, 6))
print (math.gcd(6, 12))
print (math.gcd(12, 36))
print (math.gcd(-12, -36))
print (math.gcd(5, 12))
print (math.gcd(10, 0))
print (math.gcd(0, 34))
print (math.gcd(0, 0))
math.gcd() Method returns two integers int1 and int2 Maximum common divisor of .
Tips :gcd(0,0) return 0.
2. Minimum common multiple lowest common multiple
Pay special attention here ,math There is nothing like finding the greatest common divisor in a function gcd Function to find the least common multiple !!!
lcm() Function in math It doesn't exist in the library , So we need to rely on gcd() Library to indirectly complete the work of finding the least common multiple !
Because division has a decimal point , So we need to add int Convert to an integer .
import math
a = 25
b = 35
print(type((a * b) / math.gcd(a, b)))
# <class 'float'>
import math
a = 25
b = 35
print(int((a * b) / math.gcd(a, b)))
Today is my day Python The first of the training camp 21 God , I hope to see the best of you every day
[Python Public class ] Zero base play Python The basic chapter ---- Section 1 :Python The introduction of
[Python Public class ] Zero base play Python Advanced ---- Section 1 :Python File operations in
Come on, let's have a problem swiping Carnival party Well !----【Python Training camp 】
All right. , That's all I want to share with you today
️️️ If you like , Don't be stingy with your one key triple connection ~