Divisible and not divisible: DIVNDIV (Assignment)

                     

Code: DIVNDIV

Week 8 link: https://www.codechef.com/CU1AP0008/submit/DIVNDIV

In order to beat the evil monster, you need to answer TT of its queries. In each query, the monster gives you 3 positive integers XX, YY and ZZ. For each of the monsters query you need to find the smallest positive integer KK such that:

  1. KK is strictly greater than XX
  2. KK is divisible by YY
  3. KK is not divisible by ZZ

Or determine that there is no such K

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

ll T=1;
int solve()
{
    ll a,b,c;
    int num;
    cin>>a>>b>>c;
    ll x=__gcd(b, c);
    if(x==c)
    {
        cout<<-1<<endl;
        return 0;
    }
    else
    {
        num=(a/b)+1;
        if((num*b)%c==0)
        {
            num++;
        }
    }
    cout<<num*b<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>T;
    while(T--)
    {
        solve();
    }
  return 0;
}

Power M divisibility by 7 Problem

Code: PMD7

Quick! You need to solve this problem in order to help the Chef get an A on a math exam! The problem is as follows:

You are given two integers: XX and MM. Now, you need to replace each digit of XX (let’s call them didi) with dMimod10diMmod10. Let’s call the new number YY and reverse it (explained in note 3). Check whether YY is divisible by 77.

Note 1: dMi=di⋅di⋅…⋅didiM=di⋅di⋅…⋅di (MM times) – definition of didi to the power of MM. Special case: dMi=1diM=1, when M=0M=0

Note 2: Xmod10Xmod10 is the remainder of division XX by 1010, where XX is some integer number.

Note 3: Reversing an integer is an operation that reverse the order of its digits and erase leading zeros. For example: 123123 when reversed becomes 321321 and 450450 when reversed becomes 5454.

#include <iostream>
#define ll long long int
using namespace std;
ll powr(ll x,ll n)
{
ll res=1;
while(n)
{
if(n&1)
res=res*x%10;
n=n/2;
x=x*x%10;
}
return res;
}
int main()
{
int T;
cin>>T;
while(T--)
{
ll x,m;
cin>>x>>m;
ll ld,sum=0;
ll z;
while(x>0)
{
ld=x%10;
z=powr(ld,m);
sum=10*sum+z;
x/=10;
}
if(sum%7==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
 }
return 0;
}