Educational Codeforces Round 5 E. Sum of Remainders (思维题)

题目链接:http://codeforces.com/problemset/problem/616/E

题意很简单就不说了。

因为n % x = n - n / x * x

所以答案就等于 n * m - (n/1*1 + n/2*2 ... n/m*m)

在根号n复杂度枚举x,注意一点当m>n时,后面一段加起来就等于0,就不用再枚举了。

中间一段x1 ~ x2 的n/x可能相等,所以相等的一段等差数列求和。

 1 //#pragma comment(linker, "/STACK:102400000, 102400000")
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <cmath>
 9 #include <ctime>
10 #include <list>
11 #include <set>
12 #include <map>
13 using namespace std;
14 typedef __int64 LL;
15 typedef pair <int, int> P;
16 const int N = 1e5 + 5;
17 vector <LL> myset; //存储x
18 LL mod = 1e9 + 7;
19
20 int main()
21 {
22     LL n, m;
23     scanf("%lld %lld", &n, &m);
24     LL k = min(m, n);
25     myset.push_back(k);
26     for(LL i = 1; i*i <= n; ++i) {
27         myset.push_back(i);
28         if(i * i != n) {
29             myset.push_back(n/i);
30         }
31     }
32     sort(myset.begin(), myset.end());
33     LL ans = (n%mod)*(m%mod)%mod, cnt = 0;
34     for(LL i = 0; i < myset.size() && myset[i] <= k; ++i) {
35         LL temp = myset[i];
36         if(cnt) {
37             LL num;
38             if((temp - cnt) % 2)
39                 num = ((temp + cnt + 1) / 2 % mod) * ((temp - cnt) % mod) % mod;
40             else
41                 num = ((temp - cnt) / 2 % mod) * ((temp + cnt + 1) % mod) % mod;
42             num = ((n / temp) % mod * num) % mod;
43             ans = ((ans - num) % mod + mod) % mod;
44         }
45         else {
46             ans = (ans - n) % mod;
47         }
48         cnt = temp;
49     }
50     printf("%lld\n", (ans + mod) % mod);
51     return 0;
52 }

时间: 2024-10-04 17:59:51

Educational Codeforces Round 5 E. Sum of Remainders (思维题)的相关文章

Educational Codeforces Round 74 (Rated for Div. 2)补题

慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ? ? //√,×,? 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x>y)\),问能否将\(x-y\)拆成任意多个质数之和 1.任意大于\(1\)的整数\(k\)都可以用\(2\)与\(3\)的线性表示 证: 若\(k\)是偶数,显然: 若\(k\)是奇数,则\(k\)可以表示成\(k = 3 + 2*k'\),显然: 毕. #include<bits/stdc++.h&

codeforces Educational Codeforces Round 55 (Rated for Div. 2) C题 C. Multi-Subject Competition

这道题比赛时候没做出来,下来一看才发现是排序傻逼题. 把每个偏好的人做成一个vector,从大到小排序,做一个前缀和.然后将每种人数做一个桶,在桶里装每种科目选择人数为i的时候分数总和. 遍历每一维vector,把各个位置上面的vector加到sum数组中,最后sum数组里面挑出最大值. #include<bits/stdc++.h> using namespace std; typedef long long ll; vector<int> vec[100010];//vecto

Educational Codeforces Round 63 (Rated for Div. 2) B题

题目网址:https://codeforc.es/contest/1155/problem/B 题目大意:有两个人A,B博弈,在一串数字中,A先取数,B后取数,最后剩11个数的时候停止,如果第一个数是8,则A胜,反之B胜 题解:取数到最后,只剩11个数,且,A如果要赢,第一个数是8,则A显然是要尽可能的先取前面的非8数,B要先去前面的8,按照这样的策略,只需考虑前面n -10个数取到最后是否有8即可,显然是判断8的数量和其他数的数量的大小即可. 1 #include<bits/stdc++.h>

Educational Codeforces Round 63 (Rated for Div. 2) D题

题目网址:https://codeforc.es/contest/1155/problem/D 题目大意:给定n个数和一个k,可以对这n个数进行一次操作,也可以不进行,即选择某个区间中的数都乘上k,问最后最大连续子段和是多少? 题解:(鶸鶸的我是看别人的博客才解决的 ! ) 首先这道题的状态很多,对于前m个数,乘k之前的状态,乘k的状态,之和的状态都需要建立.那么分别设dp1,dp2,dp3是乘k之前,乘k时,乘k之和,前m个数最大连续子段和. 首先对于dp1,即一组数的最大子段和,显然只要是正

Educational Codeforces Round 33 (Rated for Div. 2) A题

A. Chess For Three Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game fo

Educational Codeforces Round 33 (Rated for Div. 2) B题

B. Beautiful Divisors Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes. Some example

Educational Codeforces Round 33 (Rated for Div. 2) C题&#183;(并查集变式)

C. Rumor Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it

Educational Codeforces Round 34 (Rated for Div. 2) B题【打怪模拟】

B. The Modcrab Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics

Educational Codeforces Round 78 (Rated for Div. 2) --补题

链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = {0}; int judge() { //cout<<"111"<<endl; for (int i = 0; i < 26; ++i) { if (a[i]!=b[i]) { return 0; } } return 1; } int main() { //