Fantasy of a Summation LightOJ - 1213

本文深入解析了一段使用C++编写的代码,该代码实现了将字符串转换为数字并进行模运算的过程,以判断字符串表示的数字是否能被特定数值整除。通过详细的代码解读和运行流程说明,读者可以理解如何利用C++处理字符串和执行复杂的数学运算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 总共出现的个数为K∗NKK*N^{K}KNK 则每个数贡献为 K∗NK−1K*N^{K-1}KNK1
  2. 再加一加
 #include<bits/stdc++.h>
 using namespace std;
 #define fst first
 #define sec second
 #define sci(num) scanf("%d",&num)
 #define scl(num) scanf("%lld",&num)
 #define mem(a,b) memset(a,b,sizeof a)
 #define cpy(a,b) memcopy(a,b,sizeof b)
 typedef long long LL;
 typedef pair<int,int> P;
 const int MAX_N = 510;
 const int MAX_M = 10000;
 char s[MAX_N];
 LL b;
 int main() {
     int T;
     sci(T);
     for (int cs = 1;cs <= T;cs++) {
         scanf("%s%lld",s,&b);
         if (b < 0)  b = -b;
         int loc = 0;
         if (s[0] == '-') loc++;
         int ans = 0;
         for (;s[loc] !='\0';loc++) {
             ans = ((ans * (10% b)) % b + (s[loc] - '0') % b) % b;
         }
         if (ans == 0) {
             printf("Case %d: divisible\n",cs);
         } else {
             printf("Case %d: not divisible\n",cs);
         }
 
 
     }
     return 0;
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值