L5. Basic Math for DSA and Euclidean Algorithm (1)
L5. Basic Math for DSA and Euclidean Algorithm (1)
Digit Concept
indidaally
7 to =
778
77lb
cohfleNo)
(ast &igit 91
Cpunt degik
N 7p?
Cunt 0
Cohile )
&digié: N7 (D;
Cn olley())
(D
Ceut ce nt <<;
2 Perese O nwnbe
ohile (n2o)
Autdigit N7 10,
N No
(YeYN X1o) + lst diit
Dy Ru
eyN=0
2ifevation z B) = at degi
7 9 70 r e v n - ? */o) +
7 7 . (b
779/to 77 Ye
( 1 t xto) 7 =
3 Avotin
7 1977
yhtaho n (917 KID)
Code
int main ()
tnt h
Cin zn
whileN o) {
Yeyn=
veer1o +lost digi
h hl(eMviysy
(o
Cout< rey Numbtv y
Coe
Palindvome
n 23
n: I3 3
n
olr fabe
true
olp
nurm ber
a evese a
Steps
Ker twe a num bee
Cxtrat hig
will CDmpoA
SD
Int maun C)
int n (dap=e y )
cin
dupicar n
elsends
ohile (n 7o)
(d = n(D
(ven) 1 (o+
d 0-3
Yt )
Number
Armsteng
nlc 35
N 7
37I
3+
e 39
N I63
3 + 1 639
> 4s'+
true
at/ eic
Exttt he nubevol
Diqit,4
Cot
cot P igis)
Pigits)
Su Sum + poto (lost
Srodi3it)
Hppreah
n= IS3
Surn= o
n
int 0gind
nD
Cvnt
int
n
e int fmp =
fe Cont no digit
while(temp o
(oUnt + t
trmptmp(to
(N
int Sme polotr
digit
intt digit=n7. (;
SumoPtLoert- po ( digi6, +)
to
re tawnSum ef powev= oviqin ns)
n w n b e
36
7, (2, 1?,
P1, 2, 3, 4,6,
loopm
i e r M;
it +)
ov(i=l;
(nTi-)
printi)
TC (N)
N
36 T C = o (Jm)
2 x 19
3 x 12 iopl3
N
6 6 risl; ic=q (0)
N t2X3
36 =6 36 x
print(i)
beyond AS Same pint his
pint(li)
V e i d
printDiviJor (int){
Vecor <int ? s;
le int i l ;
iee
Sqvhn); f+t)
s . psh-back (C)
(°/)(+i)
s. psh-back (i)
3
Sovt (.cgin C), ls: end ())
Yau to i ) Cout e it e
Prime Numbex
N tt , Pime
,
t3 , 13
N- Not Prm
Appmauh
bva h Jove
Cnt o
ieen; i4t)
fo(ht
(Ni-
Cne
( o t - ) Prin
ebNot Prime)
(
Bp himizeL APproaee
isPhne(intn){
boel
orint i =2; irien;
i e+)
to d
Yeunou
int moin C)
o n Pa
Cout eePrim N elie cout
e t hCocle
sime (int )
heol
/Che
e (n2 -so n ! e ))
reum alk
odd nos up b i
rum is Avisible by my
Squan roet
inYoo S9vFl)
ointi3,
iee eot; i4=2)
l n i ro)
Ychwnfa
etnd div ib
be dav
be l
ibl
femd
the ros&hes hot een
be Cn
os, the
he iPs phm
phme
odd ro,
Smalley
by
by ny
Yeun true
3
int main C) p me
or
hot
"
folnee end
ele cout ee
GuCD(Ht
N 12
N
, 12
0ut o As hishat Common fntkov (H)
e n qed (1,12)- 3
tohich 1 .
tvcy fvo os her aloays on e gte
o
20,4o) 20 2
gck
BYuk Fovt
N = 9 N2(2
Fo 2
n 9./20, +o
amio/n,na)
(Yo, 2)
i i i ce, i+ +)
n7 i c=o ff n2 7 i se o)
9cd
TC 0/min (i, n2 5)
Algpvitk
ucldta lgovi thm
N, N
toher n2
qed(,ha) 9cd (o- n,na)
boo
book
qcd(a)6) ged (a b, 6) ab
gcd (20,is
ged (5,s
gea (,5)
num Str is
oment one umber is he oher
he
the gcd
is tsts Cualynt
This to diyiding. S a hd,
a
9ed (a,6) geh(b, 7. 5))
a
cohile(a >o d b >o)
a ab
(o r) os
elte bb7. a;
2vo
(aeo)pripriat () oe becom
7
ethev nel ged
Ch pvit()
diyiSon ir hoPP en
ohen Cvev
TC>
D(TCin(a,4))