0% found this document useful (0 votes)
33 views14 pages

L5. Basic Math for DSA and Euclidean Algorithm (1)

Uploaded by

sainilovekush99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views14 pages

L5. Basic Math for DSA and Euclidean Algorithm (1)

Uploaded by

sainilovekush99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Ls

Basics Maths DSA

Digit Concept

extva.c hion o digis meas You nttd all the diaiy

indidaally

7 to =
778

77lb

sedo (ode dvy Yun c

cohfleNo)

(ast &igit 91
Cpunt degik

N 7p?

Cunt 0

Cohile )

&digié: N7 (D;
Cn olley())
(D

Ceut ce nt <<;

2 Perese O nwnbe

123 Yyo lo3 o o


P 3 20 olP= 3 ot
rey = O

ohile (n2o)

Autdigit N7 10,

N No
(YeYN X1o) + lst diit

Dy Ru

eyN=0

rty= (Yevn X1o) t lut digit


p itovahion (773)
YtvN

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) {

int lbst digit n Lo

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

he end if cwill beo


toAile doing NDaf
t skove dupitak thil
So itS impor Hot

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

need o nbe eve digi f)


e ef digit3 (So
toe
no
add i b
ada"
BEievnisn, crtrac digit 3 ,nd Cube i 27,
ot27 27
he 3um
12yald
ord Chbe tt
eraHon , ext rat digit r
Sum2 7 + (25 IS2
01-n US
tevaton,ED=1 S S2tl
noo Com Pov ongin humbev ESum o oigi
yms Avo Vmbe (ot n)
bool

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

cohileh !=o) caltalatt Swrn n p ctoe each

digit
intt digit=n7. (;

SumoPtLoert- po ( digi6, +)
to
re tawnSum ef powev= oviqin ns)
n w n b e

Pvint all Pivtsos

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

Anumber thal hos e ae tly 2


facfo

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)

bool ons isPimn)

o n Pa
Cout eePrim N elie cout
e t hCocle

sime (int )
heol

1 he rum ij less fhon 2 or even

/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

int n; cin>>n the given number


the
numbtr
given
to thek if
thuk
Callirg th nh n "
tn<" <e tnd .
T
Ue Prme (o)) f Cout ee

"
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

1,20 leep on hunt on hing

gcd (20,is

S gce (5, ) 9a(10,3

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))

You might also like