Skip to main content

Posts

Showing posts with the label প্রবলেম

Breaking The Summation Formula (Part 2)

 1. Sum of Odd numbers: 1+3+5+7+9+....+n =? where n is an odd number Solve: let, n = 3 list = 1+3+5 = 9 ; 3^2=9 or 3*3 = 9 let, n = 5 list = 1+3+5+7+9 = 25 ; 5^2 =25 or 5*5 =25 • so, summation of n odd numbers = n^2 = n*n 2.Sum of Even numbers: 2+4+6+8+10+....+n =? where n is an even number Solve: n=4, list = 2+4+6+8 = 20; sum = 4^2+4 = 20 or 4*5 =20 n=7, list = 2+4+6+8+10+12+14 = 56; sum = 7^2+7 = 56 or 7*8 = 56 • so, summation of n even numbers = n^2+n = n*(n+1)

Breaking The Summation Formula (Part 1)

 Q. f ( n ) =  - 1 + 2 - 3 + .. + ( - 1) n n .  Given n, find out f(n) Approach(1)- Bruteforce: 1. Calculation sum=n*(n+1)/2 2. loop[i=1,i=n : i+=2] odd+=i 3.ans=sum-2*odd Code: #include < bits / stdc ++. h > using namespace std ; int main (){   long long x ; cin >> x ; long long p =( x *( x + 1 ))/ 2 ; long long bad = 0 ; for ( long long i = 1 ; i <= x ; i += 2 ) bad += i ; cout << p - 2 * bad << endl ; } Approach(2)-Greedy: Basic: s=1+2+3+4+....+n Formula: sum=n*(n+1)/2= (n/2) + (n+1).2 ...

কোডফোর্সেস বেসিক প্রবলেম লিস্ট ১

IMPLEMENTATION  Problem 1: Codeforces 835A Problem 2: Codeforces 935B Problem 3: Codeforces 868A Problem 4: Codeforces 868B LOOPS (NOT NESTED) Problem 1: Codeforces 839A Problem 2: Codeforces 939A Problem 3: Codeforces 893A Problem 4: Codeforces 935A Problem 5: Codeforces 961A Problem 6: Codeforces 828A Problem 7: Codeforces 867A Problem 8: Codeforces 939B NESTED LOOPS  Problem 1: Codeforces 894A Problem 2: Codeforces 897A Problem 3: Codeforces 822B Problem 4: Codeforces 828B Problem 5: Codeforces 886A (Can also be solved using sorting) Problem 6: Codeforces 907A Problem 7: Codeforces 22B MATH Problem 1: Codeforces 869B  (Uses a loop) Problem 2: Codeforces 875A  (Uses a nested loop) Problem 3: Codeforces 922B  (Uses a nested loop)