Sunday, September 17, 2017

10139 - Factovisors

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int

const int MAX = 50000;
bool prime[MAX];
vector <int> v;

void sieve ()
{
    int i,j;

    prime[0] = prime[1] = true;
    v.pb(2);

    for (i=4; i<MAX; i+=2)
        prime[i] = true;

    for (i=3; i*i<=MAX; i+=2)
        if (!prime[i])
            for (j=i*i; j<=MAX; j+=2*i)
                prime[j] = true;

    for (i=3; i<=MAX; i+=2)
        if (!prime[i])
            v.pb(i);
}

bool isDone (int n,int p,int c)
{
    int k = 0;

    while (n)
    {
        n /= p;
        k += n;
    }

    if (k >= c)
        return true;
    else
        return false;
}

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/
    sieve ();

    int n,m,t,i,k;

    while (sf ("%d %d",&n,&m) != EOF)
    {
        if (n >= m && m > 0)
            pf ("%d divides %d!\n",m,n);
        else if (m == 0)
            pf ("%d does not divide %d!\n",m,n);
        else
        {
            vector <int> P,F;

            t = m;

            for (i=0; v[i]*v[i]<=t; i++)
            {
                if (t % v[i] == 0)
                {
                    k = 0;
                    P.pb(v[i]);

                    while (t % v[i] == 0)
                    {
                        k++;
                        t /= v[i];
                    }

                    F.pb(k);
                }
            }

            if (t > 1)
            {
                P.pb(t);
                F.pb(1);
            }

            bool val = true;
            k = P.size();

            for (i=0; i<k; i++)
            {
                if (!isDone(n,P[i],F[i]))
                {
                    val = false;
                    break;
                }
            }

            if (val)
                pf ("%d divides %d!\n",m,n);
            else
                pf ("%d does not divide %d!\n",m,n);
        }
    }

    return 0;
}

10653 - Bombs! NO they are Mines!!

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pii pair <int,int>
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int
#define endl "\n"

const int MOD = 1000000007;
const int MAX = 1000005;

int lv[1000][1000];
bool vis[1000][1000],cell[1000][1000];
int fx[] = {0,0,1,-1};
int fy[] = {1,-1,0,0};

void bfs (int row,int col,int a,int b,int c,int d)
{
    memset (vis,0,sizeof vis);
    queue <pii> q;
    q.push(pii(a,b));
    lv[a][b] = 0;
    vis[a][b] = 1;

    while (!q.empty())
    {
        pii u = q.front();
        q.pop();

        if (u.first == c && u.second == d)
        {
            cout << lv[c][d] << endl;
            break;
        }

        for (int i=0; i<4; i++)
        {
            int x = u.first+fx[i];
            int y = u.second+fy[i];

            if (x >= 0 && x < row && y >= 0 && y < col && !vis[x][y] && !cell[x][y])
            {
                vis[x][y] = 1;
                lv[x][y] = lv[u.first][u.second]+1;
                q.push(pii(x,y));
            }
        }
    }
}

int main (void)
{
    /*
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    */
    //fast;

    int row,col,R,a,b,c,d,val,l,x,i;
    string str;

    while (cin >> row >> col && row && col)
    {
        cin >> R;

        while (R--)
        {
            cin >> x >> l;

            for (i=1; i<=l; i++)
            {
                cin >> val;
                cell[x][val] = 1;
            }
        }

        cin >> a >> b >> c >> d;

        bfs (row,col,a,b,c,d);

        memset (cell,0,sizeof cell);
    }

    return 0;
}

Wednesday, September 13, 2017

10311 - Goldbach and Euler

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pii pair <int,int>
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int
#define endl "\n"

const int MOD = 1000000007;
const int MAX = 100000005;
bool prime[MAX];

void sieve ()
{
    int i,j;

    prime[0] = prime[1] = true;

    for (i=4; i<MAX; i+=2)
        prime[i] = true;

    for (i=3; i*i<=MAX; i+=2)
        if (!prime[i])
            for (j=i*i; j<MAX; j+=2*i)
                prime[j] = true;
}

int main (void)
{
    /*
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    fast;
    */
    sieve ();

    int n,h,i;

    while (sf ("%d",&n) != EOF)
    {
        bool k = false;

        if (n & 1)
        {
            if (!prime[n-2] && n > 1)
                pf ("%d is the sum of 2 and %d.\n",n,n-2);
            else
                pf ("%d is not the sum of two primes!\n",n);
        }
        else
        {
            h = n/2;

            if (!(h & 1))
                h++;

            for (i=h; i<n; i+=2)
            {
                if (!prime[i] && !prime[n-i] && i != n-i)
                {
                    pf ("%d is the sum of %d and %d.\n",n,n-i,i);
                    k = true;
                    break;
                }
            }

            if (!k)
               pf ("%d is not the sum of two primes!\n",n);
        }
    }

    return 0;
}

Tuesday, September 12, 2017

প্রোগ্রামিংয়ের খুচরো দোকান

****** কিছু গুরুত্বপূর্ণ বাংলা ব্লগ ও ওয়েবসাইট :
১৫টিরও বেশি বাংলা ব্লগের কালেকশন এখানে, http://bit.ly/2dPvaus. আছে শাফায়েত আশরাফ, ইকরাম মাহমুদ, আলাভোলা ভাইয়া, তামিম শাহরিয়ার সুবীন সহ আরো অনেক প্রোগ্রামারদের ব্লগ লিংক। ডেটা স্ট্রাকচার ও এলগোরিদম, গ্রাফ থিওরি, ডাইনামিক প্রোগ্রামিং, নাম্বার থিওরিসহ আরো কিছু এডভান্সড টপিক আলোচনা করা আছে।

আরো কিছু :
২৪। http://jakir.me
****** কিছু গুরুত্বপূর্ণ ফোরাম :
2. Reddit
10. DaniWeb
13. Docker
14. Lobsters
15. Quora
17. Coderanch 
19. Java Forum 
22. CodeHS 
25. SQLZOO 
26. Udacity
30. Github
32. Udemy
****** Various Contest Platforms & Online Judges (OJ)’s list :
1. URI
2. UVa
6. POJ
8. SPOJ
9. Timus
13. AIZU
14. USACO
16. Vjudge
17. Toph
19. ZOJ
20. ICPC Baylor
21. Hackerearth
22. ACM ICPC Live Archive
23. SSU
24. infoarena
25. Z-Trening
26. IPSC
27. uHunt
28. uDebug
29. UVa Toolkit
30. MAXimal
31. COCI


****** Online & Offline IDEs :
1. ideone
2. Ubuntu Pastebin
3. Codechef IDE
4. C++ Shell
5. Code::Blocks
6. Dev C++
7. Codepad
8. Microsoft Visual Studio

****** Youtube Channels :
GeeksforGeeks
KNOWLEDGE GATE
Khan Academy
KhanAcademyBangla
Amuls Academy
LearningLad
Mabezat Dev
Go GATE IIT
Life at Google
Gaurav Sen
Hasan Abdullah
devGeeK
Dev Skill

Dimik Computing
10 Minute School
ACM
Atique Ullah
LoveExtendsCode
AvetisG
Bappy Nur
BOCT
BQ
Cave of Programming
5567
CodeCourse
Computer Education For all
CP Solutions 
CSE Course & Other Tutorial Video
Easy Engineering Classes


****** সি , সি প্লাস প্লাস , জাভা আর পাইথন শিখার জন্য যাওয়া যেতে পারে এই লিঙ্কে

****** বাংলা ভাষার প্রোগ্রামিং রিসোর্স : https://goo.gl/FnZNKW 

****** This link seems to be very useful to me.

****** For downloading Programming and Mathematics books, click here.

কৃতজ্ঞতা :

Monday, September 11, 2017

UVa Problems List

Supereasy : 
  1. 11172 - Relational Operator
  2. 1124 - Celebrity jeopardy  
  3. 10055 - Hashmat the Brave Warrior
  4. 10071 - Back to High School Physics
  5. 10079 - Pizza Cutting
  6. 10783 - Odd Sum
  7. 10812 - Beat the Spread!
  8. 10879 - Code Refactoring
  9. 11150 - Cola
  10. 11332 - Summing Digits
  11. 11455 - Behold my quadrangle
  12. 11479 - Is this the easiest problem?
  13. 11547 - Automatic Answer
  14. 11614 - Etruscan Warriors Never Play Chess
  15. 11677 - Alarm Clock
  16. 11727 - Cost Cutting
  17. 11877 - The Coco-Cola Store
  18. 11875 - Brick Game
  19. 11854 - Egypt
  20. 11799 - Horror Dash
  21. 11777 - Automate the Grades
  22. 11764 - Jumping Mario
  23. 11936 - The Lazy Lumberjacks
  24. 11942 - Lumberjack Sequencing
  25. 11984 - A Change in Thermal Unit
  26. 12136 - Schedule of a Married Man
  27. 12149 - Feynman
  28. 12157 - Tariff Plan
  29. 12250 - Language Detection
  30. 12279 - Emoogle Balance
  31. 12372 - Packing for Holiday
  32. 12478 - Hardest Problem Ever (Easy)
  33. 12531 - Hours and Minutes
  34. 12577 - Hajj-e-Akbar
  35. 12578 - 10:6:2
  36. 12611 - Beautiful Flag
  37. 113 - Power of Cryptography
  38. 10327 - Flip Sort
  39. 10347 - Medians
  40. 11462 - Age Sort
  41. 12468 - Zapping
  42. 12646 - Zero or One
  43. 12696 - Cabin Baggage
  44. 12802 - Gift From the Gods
  45. 12992 - Huatuo's Medicine
  46. 13012 - Identifying tea
  47. 13025 - Back to the Past
  48. 11498 - Division of Nlogonia
  49. 12854 - Automated Checking Machine
  50. 12952 - Tri-du
  51. 10302 - Summation of Polynomials
  52. 13034 - Solve Everything :-)
  53. 10469 - To Carry or not to Carry
  54. 10432 - Polygon Inside A Circle
  55. 13148 - A Giveaway
  56. 591 - Box of Bricks
  57. 272 - TEX Quotes
  58. 10970 - Big Chocolate

Beginner :
  1. 458 - The Decoder
  2. 10041 - Vito's Family
  3. 10082 - WERTYU
  4. 10300 - Ecological Premium
  5. 10324 - Zeros and Ones
  6. 10110 - Light, more light
  7. 10370 - Above Average
  8. 10696 - f91
  9. 10773 - Back to Intermediate Math
  10. 10921 - Find the Telephone
  11. 11364 - Parking
  12. 11388 - GCD LCM
  13. 11461 - Square Numbers
  14. 11530 - SMS Typing
  15. 11723 - Numbering Roads
  16. 11934 - Magic Formula
  17. 12015 - Google is Feeling Lucky
  18. 12289 - One-Two-Three
  19. 12403 - Save Setu
  20. 12626 - I ❤ Pizza
  21. 12700 - Banglawash
  22. 12439 - February 29
  23. 12342 - Tax Calculator
  24. 11958 - Coming Home
  25. 11805 - Bafana Bafana
  26. 11559 - Event Planning
  27. 11219 - How old are you?
  28. 10038 - Jolly Jumpers
  29. 100 - The 3n + 1 problem
  30. 12996 - Ultimate Mango Challenge
  31. 10931 - Parity
  32. 11715 - Car
  33. 11608 - No Problem
  34. 10784 - Diagonal
  35. 10235 - Simply Emirp
  36. 10474 - Where is the Marble?
  37. 10929 - You can say 11
  38. 11292 - Dragon of Loowater
  39. 10346 - Peter's Smokes
  40. 371 - Ackermann Functions
  41. 1225 - Digit Counting
  42. 444 - Encoder and Decoder
  43. 483 - Word Scramble
  44. 575 - Skew Binary
  45. 11827 - Maximum GCD
  46. 11185 - Ternary
  47. 484 - The Department of Redundancy Department
  48. 10282 - Babelfish
  49. 10019 - Funny Encryption Method
  50. 10295 - Hay Points
  51. 10226 - Hardwood Species
  52. 11917 - Do Your Own Homework
  53. 417 - Word Index
  54. 494 - Kindergarten Counting Game
  55. 10323 - Factorial! You Must be Kidding!!!
  56. 10281 - Average Speed
  57. 10137 - The Trip
  58. 12527 - Different Digits

Easy :
  1. 374 - Big Mod
  2. 382 - Perfection
  3. 424 - Integer Inquiry
  4. 1230 - MODEX
  5. 10070 - Leap Year or Not Leap Year and ...
  6. 10106 - Product
  7. 10523 - Very Easy !!!
  8. 11879 - Multiple of 17
  9. 11970 - Lucky Numbers
  10. 10035 - Primary Arithmetic
  11. 10050 - Hartals
  12. 494 - Kindergarten Counting Game
  13. 136 - Ugly Numbers
  14. 12895 - Armstrong Number
  15. 10924 - Prime Words
  16. 12555 - Baby Me
  17. 10107 - What is the Median?
  18. 13026 - Search the Khoj
  19. 11743 - Credit Check
  20. 11057 - Exact Sum
  21. 11849 - CD
  22. 686 - Goldbach's Conjecture (II)
  23. 543 - Goldbach's Conjecture
  24. 623 - 500!
  25. 10299 - Relatives
  26. 10179 - Irreducable Basic Fractions
  27. 11417 - GCD
  28. 10948 - The primary problem
  29. 10789 - Prime Frequency
  30. 495 - Fibonacci Freeze
  31. 10494 - If We Were a Child Again
  32. 974 - Kaprekar Numbers
  33. 10176 - Ocean Deep! - Make it shallow!!
  34. 12503 - Robot Instructions
  35. 913 - Joana and the Odd Numbers
  36. 568 - Just the Facts
  37. 10098 - Generating Fast
  38. 13131 - Divisors(III)
  39. 11466 - Largest Prime Divisor
  40. 13185 - DPA Numbers I
  41. 11728 - Alternate Task
  42. 583 - Prime Factors
  43. 10338 - Mischievous Children
  44. 12068 - Harmonic Mean
  45. 12043 - Divisors II
  46. 11889 - Benefit
  47. 10042 - Smith Numbers
  48. 567 - Risk
  49. 10006 - Carmichael Numbers
  50. 11287 - Pseudoprime Numbers
  51. 10392 - Factoring Large Numbers
  52. 10815 - Andy's First Dictionary
  53. 914 - Jumping Champion

Medium :
  1. 713 - Adding Reversed Numbers
  2. 1180 - Perfect Numbers
  3. 673 - Parentheses Balance
  4. 406 - Prime Cuts
  5. 324 - Factorial Frequencies
  6. 10539 - Almost Prime Numbers
  7. 10394 - Twin Primes
  8. 10533 - Digit Primes
  9. 10579 - Fibonacci Numbers
  10. 10220 - I Love Big Numbers !
  11. 13194 - DPA Numbers II
  12. 10852 - Less Prime
  13. 10814 - Simplifying Fractions
  14. 10139 - Factovisors
  15. 12542 - Prime Substring
  16. 1210 - Sum of Consecutive Prime Numbers
  17. 884 - Factorial Factors
  18. 10311 - Goldbach and Euler
  19. 439 - Knight Moves
  20. 10653 - Bombs! NO they are Mines!!
  21. 10780 - Again Prime? No Time.
  22. 11029 - Leading and Trailing
  23. 10791 - Minimum Sum LCM

Hard :
  1. 10364 - Square
  2. 10083 - Division