【codeforces】Divisibility 红太狼 2022-09-24 02:28 190阅读 0赞 ![这里写图片描述][20160723114657129] ![这里写图片描述][20160723114705957] 只要知道n/k为n一下能被k整除的数的总和就行了。 #include<stdio.h> typedef long long ll; ll abs(ll x) { return x>0?x:-x; } int main() { ll k,a,b; while(~scanf("%I64d%I64d%I64d",&k,&a,&b)) { ll ans; if(a>0&&b>0) { ans=abs(b/k)-abs((a-1)/k); } else if(a<0&&b<0) { ans=abs(a/k)-abs((b+1)/k); } else { ans=abs(a/k)+abs(b/k)+1; } printf("%I64d\n",ans); } return 0; } [http://acm.hust.edu.cn/vjudge/contest/123213\#problem/A][http_acm.hust.edu.cn_vjudge_contest_123213_problem_A] [20160723114657129]: /images/20220720/83f5ba89f5b242d1840b3d5af4f5e892.png [20160723114705957]: /images/20220720/0dca917a451e4c5e9b2d37fb121a8e18.png [http_acm.hust.edu.cn_vjudge_contest_123213_problem_A]: http://acm.hust.edu.cn/vjudge/contest/123213#problem/A
还没有评论,来说两句吧...