1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <sstream> 5 #include <cmath> 6 #include <algorithm> 7 #include <string> 8 #include <stack> 9 #include <queue> 10 #include <vector> 11 #include <map> 12 using namespace std; 13 14 const int mod = 1e9+7; 15 16 long long int sum[1005]; 17 18 void dabiao() 19 { 20 sum[1] = 0; 21 sum[2] = 0; 22 sum[3] = 4; 23 for(int i = 4; i <= 1000; i++) 24 { 25 sum[i] = 2 * (sum[i-1] + (i-1)) % mod; 26 } 27 } 28 29 int main() 30 { 31 dabiao(); 32 int n, m, x, y; 33 while(~scanf("%d%d", &n, &m)) 34 { 35 while(m--) 36 { 37 long long int ans = 0; 38 scanf("%d%d", &x, &y); 39 for(int i = x; i <= y; i++) 40 { 41 if(i == 1) 42 { 43 ans += sum[i] + i; 44 ans = ans % mod; 45 } 46 else 47 { 48 ans += sum[i] + 2 * i; 49 ans = ans % mod; 50 } 51 } 52 printf("%lld\n", ans); 53 } 54 } 55 return 0; 56 }
刚开始只是每组和求模再求总和后求模,没想到竟然不仅要每组和求模,还要每次求和后都求模,想不到想不到,谁让题做的少。错了那么多次可得长点记性了。
原文:https://www.cnblogs.com/Anber82/p/11178754.html