Content

Showing posts with label Jan's LightOJ. Show all posts
Showing posts with label Jan's LightOJ. Show all posts

Tuesday, December 3, 2019

Probability and Expected Value (Light OJ)

Problem 1: 1027 - A Dangerous Maze 

Say, Total number of door is N.
So, probability of choosing any door is, P = 1 / N .
Total number of door which bring you back to the beginning is  N' . 
For getting out with the positive expected time is, Ex = Xi .
For getting out with the negative expected time is, Ey = abs(Xi) + E .
'E' means we have to start again!
 So, E = ( ∑Ex + ∑Ey ) / N
 => N *  E = ( ∑abs(Xi) + N' * E) [As Positive number of door + N' = N, so we add Xi to N]
 => E = ( ∑abs(Xi) ) / (N - N')




Problem 2: 1030 - Discovering Gold 

Possibility of going to 1st position is T1 = 1.
Possibility of going to 2nd position is T2 = T1 / min(n - position from it comes, 6)
Possibility of going to 3rd position is T3 = (T1/min(n - position from it comes, 6)) + (T2/min(n - position from it comes, 6))
...
Possibility of going to nth position is Tn = (Ti-6/min(n - position from it comes, 6)) + (Ti-5/min(n - position from it comes,6)) + ... + (Tn/min( n - position from it comes, 6))

Now just add up the result, E =  ∑ Ti * ai




Problem 3: 1038 - Race to 1 Again 

Let, Expected value of n for the problem is E(n).
So, E(1) = 0
      E(2) = ( (E(1) + 1) / cnt) + ( (E(2) + 1) / cnt) [i.e. Here cnt = 2 as it has two divisors]
      ....
      E(n) = ( (E(1) + 1) / cnt) + ( (E(d1) + 1) / cnt) + ... + ( (E(n/d1) + 1) / cnt) + ( (E(n) + 1) / cnt) [i.e. Here d1 is a divisor of n]
 So, after solving the above equation we get, E(n) =  ( ∑ ( E(dt) + 1 ) ) / ( cnt - 1 ) [i.e. Here dt is 't'th divisor of n and cnt is total number of divisors of n]
 



Problem 4: 1079 - Just another Robbery 

Using the concept of 0-1 Knapsack DP we can easily do this problem. We will store minimum probability to get arrested to rob a bank and then we will check with given probability.
DP[total_money + Money[i]] = min( DP[total_money + Money[i]], DP[total_money] + (1 - DP[total_money]) * P[i] )




Problem 5: 1104 - Birthday Paradox 

Bithday Paradox , read this and you will get the answer. Here I have used the generalized formula.





Some Useful Links:
Sums and Expected Value — part 1 (by Errichto) 
Sums and Expected Value — part 2 (by Errichto) 
Explaination of LOJ 1027 

Monday, June 3, 2019

Beginners Problems Light OJ Hints

1.
1000 - Greetings from LightOJ

Add a and b then print the result.

2.
1001 - Opposite Task

If n is less then 10 then print 0 and n. Else print n-10 and 10.

3.
1006 - Hex-a-bonacci

Do memorization or build tabulation form.

4.
1008 - Fibsieve`s Fantabulous Birthday

There is a pattern. We have to find the odd and even square number and the mid point of two square number. Then follow the pattern.

5.
1010 - Knights in Chessboard

Maximum number of knights that can be placed in the board considering the restrictions by giving place all knights either in white or in black squares. 
That's mean Knm = ½ * n * m [ if n*m is even]  or Knm = (½ * n * m) + 1 [if n*m is odd].
There is some special case for n = 1 or m = 1 and n = 2 or m = 2.

6.
1015 - Brush (I)

Print the summation of nonzero positive integers.

7.
1022 - Circle in Square

Find (Area of square - Area of Circle).

8.
1042 - Secret Origins

See this

9.
1045 - Digits of Factorial

Find digit of factorials by f[i] = log(i) + f[i-1], where i = 1 to 1000000, then answer will be floor(f[n]/log(base)) + 1.

10.

1053 - Higher Math

Apply a2 + b2 = c2 [Pythagoras Theorem]

11.

1069 - Lift

Check between your position and lift's position then calculate the time.

12.

1072 - Calm Down

There is a large circle with radius R and n little circles each having radius r, are placed inside on the border of the large circle.

 then, r = (R * sin(angle)) / (1+sin(angle))   where, angle = PI / n.

There is a large circle with radius R and n little circles each having radius r, are placed outside on the border of the large circle.

 then, r = (R * sin(angle)) / (1-sin(angle))    where, angle = PI / n.

13.

1107 - How Cow

Determine if x is in the range of [x1,x2] and y is in the range of [y1,y2].

14.

1109 - False Ordering

First find the divisors of each number 1 to 1000, then place them in an array according to the condition. We have to pre-calculate the whole process. To do it a thing we have to keep in mind that no number will have more than √(1000) = 32 divisors.

15.

1113 - Discover the Web 

We will use concept of stack in this problem. Take two stacks (use STL) and do whatever is said in the problem.

16.

1116 - Ekka Dokka 

 We have to find a number x such that W%(2x)==0 and N = (W / x) should be odd. x should be in 1 to 63.

17.

1133 - Array Simulation

Do the operations using simple for loops.

18.

1136 - Division by 3

Let, a positive number sequence is -
1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17...
Now digit sum from 1 to N is (N*(N+1))/2.
for N = 1, digit sum = 1 % 3 = 1 (Not the result)
      N = 2,      "         = 3 % 3 = 0 
      N = 3,      "         = 6 % 3 = 0
      N = 4,      "         = 10%3 = 1 (Not the result)
      .
      .
      .
 Now, you will get a sequence where you can get a result.

19.

1182 - Parity 

 Use __builtin_popcount(n)function.

20.

1189 - Sum of Factorials  

First pre-calculate Sum of factorials - sum[i] = sum[i-1] + fact[i], where i is 1 to 20.
Then you can't get the result (or impossible) if (sum[pos] < n && fact[pos+1] > n)here pos is the position where (f[i]<=n). Now just print the result.

21.

1202 - Bishops  

We have to think about 2 cases.
  1. If there is a bishop in black cell and another one is in white cell the we can never take one bishop to other.
  2. If both are in same color cells then we have to check whether they are in diagonally same position or not. If they are in diagonally same position then the result will be 1 otherwise 2. 
 22.

1211 - Intersection of Cubes 

[Removed from beginner category in New LOJ version.]

23.

1212 - Double Ended Queue  

Use STL deque<int>Q .


24.

1214 - Large Division 

In JAVA you can easily solve this by BigInteger. In C/C++ use string to solve this problem.

25.

1216 - Juice in the Glass


Now, there is a angle, so, we can write-

r1/(h+x) = r2/x
so,  x = (hr2)/(r1-r2)

again, r/(p+x) = r2/x
[putting the value of x]
so, r = ((p(r1-r2))/h) + r2


thus, V = (PI * p * (r2 + r22 + (r*r2)))/3

 26.

1225 - Palindromic Numbers (II)  

Check the string from the end with the beginning. If it is not same then print No.

27.

1227 - Boiled Eggs 

No hints.

28.

1241 - Pinocchio  

First we will take a = 2 then we will check each value with a. If (a != value) then cnt+=(ceil((value-a)/5))and set a = value.

29.

1249 - Chocolate Thief  

 
Each student will have exactly (total volume / n) volume chocolate. Now we will check which student has extra and which student has less than this value. 

30.
 

Isn't it (n * m) / 2 ?? Try yourself... :p
 
31.  


Lets, O is the intersection point of AC & BD and it is also the mid point of AC & BD. So, 
    (Ax + Cx) / 2 = (Bx + Dx) / 2
or, Dx = Ax + Cx - Bx
similarly, Dy = Ay + Cy - By
Now, Using Shoelace Formula we can easily get the area.
 
32.


Do you know the formula v2 = u2 + 2as and a = (v / t)? Then this is an easy physics question...just solve it.

33. 



34.


Use a count array or map to count the occurrence of letters.

35.
 
 
Convert decimal values in binary and check if they are equal or not.  Read this to know more.

36.


If you know how to check if a year is leap year or not then it is an easy problem for you.

37.


No hints.

38. 


Just implement this formula in code.

The End

Friday, May 24, 2019

1296 - Again Stone Game

Problem Link

কাগজে কলমে ১ থেকে ৩২/তার বেশি grundy number বের করলেই একটা pattern পাওয়া যাবে!! :D


1199 - Partitioning Game

Problem Link 
Concept:
Grundy’s game:
Sometimes a move in the game divides the game into sub-games that are independent
of each other. In this case, the Grundy number of the game is
                                                 mex({g1, g2,..., gn}),
where n is the number of possible moves and
                                        gk = ak,1 xor ak,2 xor ... xor ak,m,
where move k generates sub-games with Grundy numbers ak,1,ak,2,...,ak,m.
An example of such a game is Grundy’s game. Initially, there is a single
heap that contains n sticks. On each turn, the player chooses a heap and divides
it into two nonempty heaps such that the heaps are of different size. The player
who makes the last move wins the game.
Let f (n) be the Grundy number of a heap that contains n sticks. The Grundy
number can be calculated by going through all ways to divide the heap into two
heaps. For example, when n = 8, the possibilities are 1+7, 2+6 and 3+5, so
                         f (8) = mex({ f (1) xor f (7), f (2) xor f (6), f (3) xor f (5)}).
In this game, the value of f (n) is based on the values of f (1),..., f (n-1). The
base cases are f (1) xor f (2) = 0, because it is not possible to divide the heaps of 1
and 2 sticks. The first Grundy numbers are:

f (1) = 0
f (2) = 0
f (3) = 1
f (4) = 0
f (5) = 2
f (6) = 1
f (7) = 0
f (8) = 2


The Grundy number for n = 8 is 2, so it is possible to win the game. The winning
move is to create heaps 1+7, because f (1) xor f (7) = 0.

Solution:

 

Tuesday, May 21, 2019

Game Theory (Nim)

Tutorial

1186 - Incredible Chess 

  বোর্ডের মাপকে স্তুপ সংখ্যা হিসেবে বিবেচনা করবো এবং কালো গুটি থেকে সাদা গুটির দূরত্বকে (কয়টি চাল দেওয়া সম্ভব তার সংখ্যা ) পাথর সংখ্যা বিবেচনা করবো। তারপর সমস্যাটি খুব সহজেই নিম অ্যালগোরিদম দিয়ে সমাধান করা যায়।

1192 - Left Right

সাদা এবং ধূসর বর্ণের ঘরের মধ্যবর্তী দূরত্বকে পাথরের সংখ্যা এবং প্রতিটি ধূসর-সাদা এর মধ্যের দূরত্বকে একটি করে স্তম্ভ বিবেচনা করবো।

1247 - Matrix Game 

Tutorial এ hints দেওয়া আছে।

1253 - Misere Nim 

 Tutorial এ hints দেওয়া আছে।

1393 - Crazy Calendar 

(1, 1) হতে (row, column) point এ যেতে যে কয়টা ঘর অতিক্রম করতে হয় সেটাই হচ্ছে পাথরের সংখ্যা ।

Wednesday, February 27, 2019

1049 - One Way Roads

Problem Link

Considering the below graph, we get

  6
 1 5 4
 5 3 8
 2 4 15
 1 6 16
 2 3 23
 4 6 42

 


 
















If we start traversing the graph from node 1, then we will traverse like 1->5->3->2->4->6->1 (as a ring).
For 3<-2 we will take its weight negative for 3->2.






















Now we will add the negative weights and positive weights  respectively then print the minimum between them.

Solution:

1112 - Curious Robin Hood

Problem Link

Solution:

1082 - Array Queries

Problem Link

Solution:

Monday, February 25, 2019

1012 - Guilty Prince

Problem Link


Flood Fill এই algorithm দিয়ে এটা সহজেই solve করা যায়।
Same Category : C. Connect  (Codeforces)


Solution:

Thursday, November 22, 2018

1048 - Conquering Keokradong

Problem Link

K এর মধ্যে possible এমন  walking distance এর maximum টা বের করতে হবে এবং যা হবে সবচাইতে minimize করা value.
1st Test Case:
4 3
7
------   K = 1
2     |
       |   -> 8 এর চাইতে minimize possible না
6     |
------   K = 2
4
------   K = 3
5

তাই এটা binary search দিয়ে খুব সহজেই সল্ভ করা সম্ভব।

My Solution:

#include<bits/stdc++.h>
using namespace std;
int a[1005], total_dist, n, k, highest, mx;

bool check(int x)
{
    int part = 0, sum = 0;
    for(int i = 0; i <= n; i++)
    {
        sum+=a[i];
        if(sum > x)
        {
            sum = a[i];
            part++;
        }
    }
    return part<=k;
}

void BS()
{
    int Left = mx, Right = total_dist, mid;
    while(Left<=Right)
    {
        mid = (Left+Right)/2;
        if(check(mid))
        {
            highest = mid;
            Right = mid - 1;
        }
        else
            Left = mid + 1;
    }
}

int main()
{
    int T;
    cin>>T;
    for(int t = 1; t <= T; t++)
    {
        total_dist = 0;
        mx = 0;
        memset(a, 0, sizeof(a));
        cin>>n>>k;
        for(int i = 0; i <= n; i++)
        {
            cin>>a[i];
            total_dist += a[i];
            mx = max(mx,a[i]);
        }
        BS();
        cout<<"Case "<<t<<": "<<highest<<endl;
        int flag = 0, cnt = 0;
        for(int i = 0; i <= n; i++)
        {
            flag+=a[i];
            if(flag > highest || cnt+(n+1-i)==k)
            {
                cout<<flag-a[i]<<endl;
                flag = a[i];
                cnt++;
            }
        }
        cout<<flag<<endl;
    }
    return 0;
}


Thursday, September 27, 2018

1009 - Back to Underworld

Problem Link

এটি Bipartite Graph এর প্রোব্লেম। শুধু Bipartite এর মধ্যে দুইটি সেট এর মধ্যে যার nodes বেশি তা count করলেই solution পাওয়া যাবে।

টেস্ট কেস ২:
3
1 2
2 3
4 2

ধরি, 1 হচ্ছে Vampire, তাহলে 2 অবশ্যই Lykan । যেহেতু 2 Lykan তো 3 Vampire।
তাই আমরা বলতে পারি 1,3,4 হচ্ছে Vampires এবং 2 Lykan। আর এদের মধ্যে Vampires এর সংখ্যা সর্বাধিক ।
(আমরা যদি 1 কে Lykan ধরে করতাম তাহলে Lykan এর সংখ্যা সর্বাধিক হইত, কোনটা সর্বাধিক হচ্ছে এটাতে আমার কোনো মাথা ব্যাথা নেই শুধু সর্বাধিক মানটা লাগবে।)

এখন আমরা একটা গ্রাফ আঁকব যেখানে 1 এর সাথে 2 connected, 2 এর সাথে 3 এবং 4। অর্থাৎ , Graph এর edge গুলা তাদের মধ্যের Rival Relation প্রকাশ করবে।  2 Lykan হলে এর adjacent node গুলা হবে Vampires ।   সুতরাং এখনে আমার কাজ হবে দুইটা- প্রথমত আমি Lykan & Vampires এর সংখ্যা count করব তারপর তাদের max value add করব। আর এই max value টাই হবে কাঙ্ক্ষিত result...

My Code:

#include<bits/stdc++.h>
using namespace std;
#define MAX 20001
#define Vampires 1
#define Lykans 2
vector<int>edge[MAX];
int visited[MAX];

int BFS(int source)
{
    int No_V = 0,No_L = 0;
    queue<int>q;
    q.push(source);
    visited[source] = Vampires;
    No_V++;

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

        for(int i = 0; i < edge[u].size(); i++)
        {
            int v = edge[u][i];
            if(visited[v]==0)
            {
                if(visited[u]==Vampires)
                {
                    visited[v] = Lykans;
                    No_L++;
                }
                else
                {
                    visited[v] = Vampires;
                    No_V++;
                }
                q.push(v);
            }
        }
    }

    return max(No_L,No_V);
}

int main()
{
    int T;
    cin>>T;
    for(int t = 1; t <= T; t++)
    {
        int n, mx = 0;
        scanf("%d",&n);
        memset(visited, 0, sizeof(visited));
        for(int i = 0; i < MAX; i++)
            edge[i].clear();

        for(int i = 0; i < n; i++)
        {
            int u, v;
            scanf("%d %d",&u,&v);
            edge[u].push_back(v);
            edge[v].push_back(u);
        }

        for(int i = 1; i < MAX; i++)
        {
            if(!edge[i].empty() && visited[i]==0)
            {
                mx+=BFS(i);
            }
        }

        printf("Case %d: %d\n",t,mx);
    }

    return 0;
}

Thursday, September 13, 2018

1042 - Secret Origins

Problem Link

15 =     1111 (Binary)
23 =   10111 (Binary)
27 =   11011 (Binary)
29 =   11101 (Binary)
30 =   11110 (Binary)
39 = 100111 (Binary)

এখানে, 15  এর Onoroy value 23 , 23 এর Onoroy value 27  ,  27 এর Onoroy value 29 ,  29 এর 30 ,  30 এর  39 , ...
এখানে Decimal Number দেখে কোনো pattern পাওয়া যায় না, কিন্তু Binary Number খেয়াল করলে একটা pattern খুজে পাওয়া যায়। এখানে Binary Number কে দুই ভাগে ভাগ করে result বের করতে হবে। বামদিকে 1 বাড়িয়ে সংখ্যাটিকে বর্তমান সংখ্যার চাইতে বড় করতে হবে এবং ডান দিকের 1 বাড়িয়ে পরের সংখ্যার চাইতে ছোট রাখতে হবে। লিঙ্কটি দেখলে বেপারটা আরো ক্লিয়ার হবে।


My Solution:


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

int main()
{
    int T;
    long long N, lowestBit, leftBits, changedBits, rightBits;
    cin>>T;
    for(int t = 1; t <= T; t++)
    {
        cin>>N;
        lowestBit = N & -N;
        leftBits = N + lowestBit;
        changedBits = N ^ leftBits;
        rightBits = (changedBits / lowestBit) >> 2;
        N = leftBits | rightBits;
        cout<<"Case "<<t<<": "<<N<<endl;
    }

    return 0;
}

Wednesday, September 12, 2018

1008 - Fibsieve`s Fantabulous Birthday

Problem Link

ভালমত দুইটি জিনিস খেয়াল করতে হবে -
        ১)  সংখ্যাগুলো একটা বর্গের ছাঁচ তৈরী করে।
        ২)  জোড় এবং বিজোড় বর্গ সংখ্যাগুলা বিপরীতক্রমে সাজানো থাকে তাই তাদের হিসেব করার শর্তও বিপরীত হবে।
তো এখন শুধু কাজটা হবে ছাঁচটা খুজে বের করা। :p

My Solution:

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

int main()
{
    int T;
    ll s, mid, p, q, p1, q1;
    cin>>T;
    for(int t = 1; t <= T; t++)
    {
        cin>>s;
        p = ceil(sqrt(s));
        q = p - 1;
        p1 = p*p;
        q1 = q*q;
        mid = (p1+q1+1)/2;
        if(p%2)
        {
            if(s==mid)
                cout<<"Case "<<t<<": "<<p<<" "<<p<<endl;
            else if(s>mid)
            {
                cout<<"Case "<<t<<": "<<p1-s+1<<" "<<p<<endl;
            }
            else if(s<mid)
            {
                cout<<"Case "<<t<<": "<<p<<" "<<s-q1<<endl;
            }
        }
        else
        {
            if(s==mid)
                cout<<"Case "<<t<<": "<<p<<" "<<p<<endl;
            else if(s>mid)
            {
                cout<<"Case "<<t<<": "<<p<<" "<<p1-s+1<<endl;
            }
            else if(s<mid)
            {
                cout<<"Case "<<t<<": "<<s-q1<<" "<<p<<endl;
            }
        }
    }

    return 0;
}

Sunday, August 26, 2018

1109 - False Ordering

Problem Link

প্রথমত যে সংখ্যাটি দেওয়া হবে তার ডিভিজর এর সংখ্যা বের করতে হবে। এখন প্রতিটির জন্য এইভাবে বের করে হিসাব করতে অনেক সময় লাগবে ,যার জন্য TLE খেতে হবে। এইজন্য pre-calculation করে নিব। ১ থেকে ১০০০ পর্যন্ত সব কয়টি সংখ্যার জন্য ডিভিজর এর সংখ্যা বের করে একটা array তে রাখব, তারপর ওই সংখ্যাগুলো প্রব্লেমে দেওয়া শর্ত অনুযায়ী আরেটা array তে সাজিয়ে রাখব।

My Solution in C++:

#include<bits/stdc++.h>
using namespace std;
vector<int>v[1001];
vector<int>m[33];
vector<int>ans;

void cal()
{
    for(int n = 1; n <= 1000; n++)
    {
        int k = n;
        for (int i=1; i<=sqrt(n); i++)
        {
            if (n%i==0)
            {
                if (n/i == i)
                    v[k].push_back(i);
                else
                {
                    v[k].push_back(i);
                    v[k].push_back(n/i);
                }
            }
        }
    }
    for(int i = 1; i <= 32; i++)
    {
        for(int j = 1; j <= 1000; j++)
        {
            int q = v[j].size();
            if(i==q)
            {
                m[i].push_back(j);
            }
        }
    }
    for(int i = 1; i <= 32; i++)
    {
        for(int s = m[i].size()-1; s >=0; s--)
        {
            ans.push_back(m[i][s]);
        }
    }
}

int main()
{
    cal();
    int T, n;
    cin>>T;
    for(int t = 1; t <= T; t++)
    {
        cin>>n;
        cout<<"Case "<<t<<": "<<ans[n-1]<<endl;
    }

    return 0;
}

Friday, August 24, 2018

1138 - Trailing Zeroes (III)

Problem Link

বাইসেকশন মেথড ব্যবহার করে খুব সহজেই এর সমাধান করা যাবে। ০ থেকে ১০^৯ পর্যন্ত চেক করলেই আন্সার পাওয়া যায়।

My Solution in C++:

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

long long check(long long x)
{
    long long n = 0;
    while(x)
    {
        n += x/5;
        x = x/5;
    }

    return n;
}

long long BS(long long x)
{
    long long left = 0, right = 10000000000, mid, ans = 0;
    while(right>=left)
    {
        mid = (left+right) >> 1;
        if(check(mid) >= x)
        {
            if(check(mid)==x)
                ans = mid;
            right = mid - 1;
        }
        else
            left = mid + 1;
    }

    return ans;
}

int main()
{
    int T,t;
    long long Q;
    cin>>T;
    for(t = 1; t <= T; t++)
    {
        cin>>Q;
        if(BS(Q)!=0)
            cout<<"Case "<<t<<": "<<BS(Q)<<endl;
        else
            cout<<"Case "<<t<<": impossible"<<endl;
    }

    return 0;
}

1043 - Triangle Partitioning

Problem Link

আমরা এটা দুইটা মেথডে সল্ভ করতে পারি-
১) জ্যামিতিক
২) বাইসেকশন

আমি এখানে জ্যামিতিক উপায়ে সল্ভ করেছি। সল্ভ করার আগে একটা উপপাদ্য আমাদের জানতে হবে আর সেটা হচ্ছে -
দুইটি সদৃশ ত্রিভুজক্ষেত্রের ক্ষেত্রফলদ্বয়ের অনুপাত তাদের যেকোনো দুই অনুরূপ বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলদ্বয়ের অনুপাতের সমান।(উ.গ.শ্রে-(৯-১০)-- উপপাদ্য ৩.৯)

অর্থাৎ, 
ত্রিভুজ ABC / ত্রিভুজ ADE = AB^2 / AD^2

এখন ধরি, ADE ঃ DEBC = m ঃ n
        বা, ADE ঃ ABC = m ঃ m+n
        বা, AD^2 ঃ AB^2 = m ঃ m+n
        বা, AD ঃ AB = sqrt(m) ঃ sqrt(m+n)
        বা, AD =  ( sqrt(m) ঃ sqrt(m+n) ) * AB
                                                                      [Solved]


My Solution in C++:

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

int main()
{
    int T,t;
    double ab,ac,bc,r,x,ad;
    cin>>T;
    for(t=1; t<=T; t++)
    {
        cin>>ab>>ac>>bc>>r;
        x = sqrt(r)/sqrt(r+1);
        ad = x * ab;
        cout<<"Case "<<t<<": "<<setprecision(10)<<ad<<endl;
    }

    return 0;
}

1214 - Large Division

Problem Link

এই লিঙ্কটা একবার দেখে আসি তাহলে এই প্রব্লেমটা করতে আর সময় লাগবে না আশা করি।

My Solution in C++:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int T,t;
  7.  
  8.     cin>>T;
  9.  
  10.     for(t=1; t<=T; t++)
  11.     {
  12.         char bhajjo[1000];
  13.         long long i,bhajok,bhagshesh=0; /// 18| 2592 | 144
  14.         scanf("%s",bhajjo);            /// bhajok | bhajjo | bhagfol
  15.         scanf("%lld",&bhajok);
  16.  
  17.         int l=strlen(bhajjo);
  18.  
  19.         for(i=0; i<l; i++)
  20.         {
  21.             if(bhajjo[i]=='-')
  22.                 bhajjo[i]='0';
  23.         }
  24.  
  25.         for(i=0; i<l; i++)
  26.         {
  27.             bhagshesh = ((bhagshesh*10) + (bhajjo[i]-'0') )%bhajok; // Amra character theke integer e convert kore nilam '0' biyog kore
  28.         }
  29.  
  30.         if(bhagshesh==0)
  31.             cout<<"Case "<<t<<": divisible"<<endl;
  32.         else
  33.             cout<<"Case "<<t<<": not divisible"<<endl;
  34.     }
  35.  
  36.     return 0;
  37. }