Uva 11344 - The Huge One
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL checkDivisibility(string x, LL mod)
{
LL i,num=0;
for(i=0;i<x.size();i++)
{
// Modular Arithmetic [ ( (a*10) + digit ) % mod ] = ( ( (a*10) % mod ) + (digit % mod) ) % mod
num = (( num % mod) * (10 % mod)) % mod; // ( (a*10) % mod )
num = num + ((x[i] - 48) % mod); // (digit % mod)
num %= mod; // (digit % mod) % mod
}
return num;
}
int main()
{
string s;
int t;
cin >> t;
while(t--)
{
bool fl=false;
cin >> s;
int n;
cin >> n;
while(n--)
{
int x;
cin >> x;
if(checkDivisibility(s,x))
{
fl=true;
}
}
if(fl)
{
cout << s << " - " << "Simple." << endl;
}
else
{
cout << s << " - " << "Wonderful." << endl;
}
}
return 0;
}
using namespace std;
typedef long long LL;
LL checkDivisibility(string x, LL mod)
{
LL i,num=0;
for(i=0;i<x.size();i++)
{
// Modular Arithmetic [ ( (a*10) + digit ) % mod ] = ( ( (a*10) % mod ) + (digit % mod) ) % mod
num = (( num % mod) * (10 % mod)) % mod; // ( (a*10) % mod )
num = num + ((x[i] - 48) % mod); // (digit % mod)
num %= mod; // (digit % mod) % mod
}
return num;
}
int main()
{
string s;
int t;
cin >> t;
while(t--)
{
bool fl=false;
cin >> s;
int n;
cin >> n;
while(n--)
{
int x;
cin >> x;
if(checkDivisibility(s,x))
{
fl=true;
}
}
if(fl)
{
cout << s << " - " << "Simple." << endl;
}
else
{
cout << s << " - " << "Wonderful." << endl;
}
}
return 0;
}
Comments
Post a Comment