H - Large Division(大数取模)

#include
#include
#include
#include
#include
#include
#include
#include
#include
using i64 = int64_t;
using namespace std;
#define endl '\n'
#define int i64
const int maxn = 1e6 + 10;
int a = 1, n,ans;
void solve()
{
    int t, b;
    string str;
    cin >> str >> b; 
    if(str[0] == '-')str.erase(0,1);
    int len = str.length();
    b = abs(b);ans = (str[0] ^ 48);
    for(int i = 1;i < len;i++)
    {
            ans = ans * 10 + str[i] - '0';
            ans %= b;
    }
    ans == 0 ? printf("Case %lld: divisible\n",a++) : printf("Case %lld: not divisible\n",a++);
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while(T--)
        solve();
    return 0;
}

 

你可能感兴趣的:(ACM练习题集,c++,算法,开发语言)