CP Lecture 1

Visvesvaraya National Institute of Technology
COMPETITIVE
PROGRAMMING
WORKSHOP
Let’s Start With Maths...
To become a Pupil you need two things Maths and Maths
1.Prime Testing
2. Divisors and Prime Factors
3.GCD and LCM
4.Binary Expo
5.Modular Arithmetic
6.Permutations
CONTENTS
3 Methods
Naive
Square root
Iterate on prime
1.
2.
3.
PRIME TESTING
1.
QUESTIONS
FACTORS
24 →1 2 3 4 6 8 12 24
**(the power of brute force)
GCD AND LCM
int gcd(int a,int b)
{
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
Binary Expo
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
Permutations
Modular Arithmetic
( a + b) % c = ( ( a % c ) + ( b % c ) ) % c
( a * b) % c = ( ( a % c ) * ( b % c ) ) % c
( a – b) % c = ( ( a % c ) – ( b % c ) ) % c
1.
2.
3.
Factorial wala example
Homework
CP Lecture 1
1 of 12

Recommended

CP L1 by
CP L1CP L1
CP L1AlokRanjan822776
5 views12 slides
Cryptography and Network Security Principles and Practice.docx by
Cryptography and Network Security Principles and Practice.docxCryptography and Network Security Principles and Practice.docx
Cryptography and Network Security Principles and Practice.docxAbhinav816839
17 views21 slides
DAA Practical -1.ppt by
DAA Practical -1.pptDAA Practical -1.ppt
DAA Practical -1.pptChiragAhuja44
4 views12 slides
NumberTheory.ppt by
NumberTheory.pptNumberTheory.ppt
NumberTheory.pptDhandhan16
27 views37 slides
Modular arithmetic by
Modular arithmeticModular arithmetic
Modular arithmeticJanani S
1.2K views22 slides
Week 5 by
Week 5Week 5
Week 5준성 조
611 views23 slides

More Related Content

Similar to CP Lecture 1

2.ppt by
2.ppt2.ppt
2.pptTapodhirAcharjee2
4 views52 slides
SYLLABUS_COMPLEX NUMBER.pdf by
SYLLABUS_COMPLEX NUMBER.pdfSYLLABUS_COMPLEX NUMBER.pdf
SYLLABUS_COMPLEX NUMBER.pdfenggeng7
9 views21 slides
Ch04 by
Ch04Ch04
Ch04Joe Christensen
2.1K views30 slides
Write a recursive implementation of Euclids algorithm for finding t.docx by
 Write a recursive implementation of Euclids algorithm for finding t.docx Write a recursive implementation of Euclids algorithm for finding t.docx
Write a recursive implementation of Euclids algorithm for finding t.docxajoy21
7 views6 slides
Smu bca sem 1 winter 2014 assignments by
Smu bca sem 1 winter 2014 assignmentsSmu bca sem 1 winter 2014 assignments
Smu bca sem 1 winter 2014 assignmentssmumbahelp
102 views3 slides
Technical aptitude test 2 CSE by
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSESujata Regoti
1.4K views23 slides

Similar to CP Lecture 1(20)

SYLLABUS_COMPLEX NUMBER.pdf by enggeng7
SYLLABUS_COMPLEX NUMBER.pdfSYLLABUS_COMPLEX NUMBER.pdf
SYLLABUS_COMPLEX NUMBER.pdf
enggeng79 views
Write a recursive implementation of Euclids algorithm for finding t.docx by ajoy21
 Write a recursive implementation of Euclids algorithm for finding t.docx Write a recursive implementation of Euclids algorithm for finding t.docx
Write a recursive implementation of Euclids algorithm for finding t.docx
ajoy217 views
Smu bca sem 1 winter 2014 assignments by smumbahelp
Smu bca sem 1 winter 2014 assignmentsSmu bca sem 1 winter 2014 assignments
Smu bca sem 1 winter 2014 assignments
smumbahelp102 views
Technical aptitude test 2 CSE by Sujata Regoti
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
Sujata Regoti1.4K views
important C questions and_answers praveensomesh by praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
praveensomesh5.3K views
Swartz Factoring by swartzje
Swartz FactoringSwartz Factoring
Swartz Factoring
swartzje1.6K views
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c... by Demetrio Ccesa Rayme
Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc... by Demetrio Ccesa Rayme
Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc...
Dynamic Programming Matrix Chain Multiplication by KrishnakoumarC
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
KrishnakoumarC18 views
Dti2143 chapter 3 arithmatic relation-logicalexpression by alish sha
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
alish sha515 views
Ged Mathematical Test by Tutor Ferry
Ged Mathematical Test Ged Mathematical Test
Ged Mathematical Test
Tutor Ferry1.6K views
dynamic programming complete by Mumtaz Ali (03154103173) by Mumtaz Ali
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali696 views
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c... by Demetrio Ccesa Rayme
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
555_Spring12_topic06.ppt by SnehSinha6
555_Spring12_topic06.ppt555_Spring12_topic06.ppt
555_Spring12_topic06.ppt
SnehSinha63 views

Recently uploaded

SWM L1-L14_drhasan (Part 1).pdf by
SWM L1-L14_drhasan (Part 1).pdfSWM L1-L14_drhasan (Part 1).pdf
SWM L1-L14_drhasan (Part 1).pdfMahmudHasan747870
48 views150 slides
performance uploading.pptx by
performance uploading.pptxperformance uploading.pptx
performance uploading.pptxSanthiS10
7 views18 slides
SWM L15-L28_drhasan (Part 2).pdf by
SWM L15-L28_drhasan (Part 2).pdfSWM L15-L28_drhasan (Part 2).pdf
SWM L15-L28_drhasan (Part 2).pdfMahmudHasan747870
28 views93 slides
FLOW IN PIPES NOTES.pdf by
FLOW IN PIPES NOTES.pdfFLOW IN PIPES NOTES.pdf
FLOW IN PIPES NOTES.pdfDearest Arhelo
90 views10 slides
Deutsch Crimping by
Deutsch CrimpingDeutsch Crimping
Deutsch CrimpingIwiss Tools Co.,Ltd
19 views7 slides
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptx by
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptxSTUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptx
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptxAnnieRachelJohn
25 views34 slides

Recently uploaded(20)

performance uploading.pptx by SanthiS10
performance uploading.pptxperformance uploading.pptx
performance uploading.pptx
SanthiS107 views
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptx by AnnieRachelJohn
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptxSTUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptx
STUDY OF SMART MATERIALS USED IN CONSTRUCTION-1.pptx
AnnieRachelJohn25 views
A multi-microcontroller-based hardware for deploying Tiny machine learning mo... by IJECEIAES
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
IJECEIAES10 views
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th... by ahmedmesaiaoun
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
ahmedmesaiaoun12 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
What is Whirling Hygrometer.pdf by IIT KHARAGPUR
What is Whirling Hygrometer.pdfWhat is Whirling Hygrometer.pdf
What is Whirling Hygrometer.pdf
IIT KHARAGPUR 11 views
Extensions of Time - Contract Management by brainquisitive
Extensions of Time - Contract ManagementExtensions of Time - Contract Management
Extensions of Time - Contract Management
brainquisitive15 views
13_DVD_Latch-up_prevention.pdf by Usha Mehta
13_DVD_Latch-up_prevention.pdf13_DVD_Latch-up_prevention.pdf
13_DVD_Latch-up_prevention.pdf
Usha Mehta9 views
Design and analysis of a new undergraduate Computer Engineering degree – a me... by WaelBadawy6
Design and analysis of a new undergraduate Computer Engineering degree – a me...Design and analysis of a new undergraduate Computer Engineering degree – a me...
Design and analysis of a new undergraduate Computer Engineering degree – a me...
WaelBadawy652 views
An approach of ontology and knowledge base for railway maintenance by IJECEIAES
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenance
IJECEIAES12 views

CP Lecture 1