File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 11---
22title : 2894. 分类求和并作差
3- date : ' 2025.05.27 23:52'
3+ date : " 2025.05.27 23:52"
44tags :
55 - - Python
66 - - answer
77 - - typescript
88abbrlink : 66adcc9e
9+ docId : y0ntwlksnvj7ymuapqvkvmwr
910---
10- [ 2894. 分类求和并作差] ( https://leetcode.cn/problems/divisible-and-non-divisible-sums-difference/description/ )
1111
12+ [ 2894. 分类求和并作差] ( https://leetcode.cn/problems/divisible-and-non-divisible-sums-difference/description/ )
1213
1314# Thought
1415
1516** 题意:**
1617在 $[ 1, n] $ 中,求所有不能被 $m$ 整除的数的总和与能被整除的数的总和之差。
1718
1819** 思路推导:**
20+
19211 . 总和:
2022 $S_ {\text{total}} = \sum_ {i=1}^{n} i = \frac{n(n+1)}{2}$
2123
@@ -31,6 +33,7 @@ abbrlink: 66adcc9e
3133 $= \frac{n(n+1)}{2} - m \cdot \left\lfloor \frac{n}{m} \right\rfloor(\left\lfloor \frac{n}{m} \right\rfloor+1)$
3234
3335# Code
36+
3437``` python
3538class Solution :
3639 def differenceOfSums (self , n : int , m : int ) -> int :
@@ -40,5 +43,6 @@ class Solution:
4043```
4144
4245``` typescript
43- const differenceOfSums = (n : number , m : number ): number => - m * ((1 + Math .floor (n / m )) * Math .floor (n / m )) + (n * (n + 1 ) >> 1 );
44- ```
46+ const differenceOfSums = (n : number , m : number ): number =>
47+ - m * ((1 + Math .floor (n / m )) * Math .floor (n / m )) + ((n * (n + 1 )) >> 1 );
48+ ```
Original file line number Diff line number Diff line change 11{
22 "repo" : " InvolutionHell/involutionhell" ,
3- "generatedAt" : " 2025-12-11T03:06:09.120Z " ,
3+ "generatedAt" : " 2025-12-12T03:07:57.932Z " ,
44 "docsDir" : " app/docs" ,
5- "totalDocs" : 139 ,
5+ "totalDocs" : 140 ,
66 "results" : [
77 {
88 "docId" : " ue27z7z95yzw3lhhfj7nit1c" ,
23742374 }
23752375 ]
23762376 },
2377+ {
2378+ "docId" : " y0ntwlksnvj7ymuapqvkvmwr" ,
2379+ "path" : " app/docs/CommunityShare/Leetcode/2894. 分类求和并作差.md" ,
2380+ "contributorStats" : {
2381+ "114939201" : 1
2382+ },
2383+ "contributors" : [
2384+ {
2385+ "githubId" : " 114939201" ,
2386+ "contributions" : 1 ,
2387+ "lastContributedAt" : " 2025-12-12T03:00:48.000Z" ,
2388+ "login" : " longsizhuo" ,
2389+ "avatarUrl" : " https://avatars.githubusercontent.com/u/114939201?v=4" ,
2390+ "htmlUrl" : " https://github.com/longsizhuo"
2391+ }
2392+ ]
2393+ },
23772394 {
23782395 "docId" : " r12u8o7j73oxhbvgphi939fb" ,
23792396 "path" : " app/docs/CommunityShare/Leetcode/3072. 将元素分配到两个数组中 II_translated.md" ,
24122429 "docId" : " jv8qj3ljyr2uomaehnv0l77k" ,
24132430 "path" : " app/docs/CommunityShare/Leetcode/42.md" ,
24142431 "contributorStats" : {
2415- "114939201" : 1
2432+ "114939201" : 2
24162433 },
24172434 "contributors" : [
24182435 {
24192436 "githubId" : " 114939201" ,
2420- "contributions" : 1 ,
2421- "lastContributedAt" : " 2025-12-11T03:00:46 .000Z" ,
2437+ "contributions" : 2 ,
2438+ "lastContributedAt" : " 2025-12-11T03:06:10 .000Z" ,
24222439 "login" : " longsizhuo" ,
24232440 "avatarUrl" : " https://avatars.githubusercontent.com/u/114939201?v=4" ,
24242441 "htmlUrl" : " https://github.com/longsizhuo"
You can’t perform that action at this time.
0 commit comments