fork download
  1. #include <bits/stdc++.h>
  2. #define task "1"
  3. #define int long long
  4. #define double long double
  5. #define ii pair<int,int>
  6. #define fi first
  7. #define se second
  8. #define c_bit(i) __builtin_popcountll(i)
  9. #define Bit(mask,i) ((mask >> i) & 1)
  10. #define onbit(mask,i) ((mask) | (1LL << i))
  11. #define offbit(mask,i) ((mask) &~ (1LL << i))
  12. using namespace std;
  13. const int maxn = 1e5 + 5;
  14. const int oo = 1e18;
  15. const int mod = 1e9 + 7;
  16. const int dx[] = {0,1,0,-1} , dy[] = {1,0,-1,0};
  17. int t, pref[2005][2005];
  18. int get(int x, int y, int u, int v)
  19. {
  20. return pref[u][v] - pref[x - 1][v] - pref[u][y - 1] + pref[x - 1][y - 1];
  21. }
  22. int sum(const int &x, const int &y)
  23. {
  24. int res = x + y;
  25. if(res >= mod) res -= mod;
  26. return res;
  27. }
  28. void add(int &x, const int &y)
  29. {
  30. if((x += y) >= mod) x -= mod;
  31. }
  32. int diff(const int &x, const int &y)
  33. {
  34. int res = x - y;
  35. if(res < 0) res += mod;
  36. return res;
  37. }
  38. main()
  39. {
  40. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  41. if(fopen(task".inp","r")){
  42. freopen(task".inp","r",stdin);
  43. freopen(task".out","w",stdout);
  44. }
  45. cin >> t;
  46. for(int i = 1;i <= 2003;i ++) for(int j = 1;j <= 2003;j ++){
  47. pref[i][j] = pref[i][j - 1] + (__gcd(i, j) == 1 ? 1LL * i * j : 0);
  48. }
  49. int pre = t;
  50. while(t --){
  51. int a, b, c, d, k; cin >> a >> b >> c >> d >> k;
  52. // if(max(b, d) <= 2000 && pre <= 2){
  53. // int res = 0;
  54. // for(int i = a;i <= b;i ++) for(int j = c;j <= d;j ++) if(__gcd(i, j) == k) res += 1LL * i * j;
  55. // cout << res % mod << '\n';
  56. // continue;
  57. // }
  58. if(k == 1){
  59. int res = 0;
  60. for(int i = a;i <= b;i ++) add(res, pref[i][d] - pref[i][c - 1]);
  61. cout << res<< '\n';
  62. continue;
  63. }
  64. }
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0.4s 35056KB
stdin
1
100 1000 25 300 1
stdout
484351826