zoukankan      html  css  js  c++  java
  • HAOI2011 Problem b

    传送门

    做过上一道题之后,这个题就没啥难度了。就是加了个枚举的下界。

    就像维护二维前缀和一样,直接把结果加加减减即可,具体方法和上一题一样。直接看代码。

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<iostream>
    #include<cmath>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #define rep(i,a,n) for(int i = a;i <= n;i++)
    #define per(i,n,a) for(int i = n;i >= a;i--)
    #define enter putchar('
    ')
    #define fr friend inline
    #define y1 poj
    #define mp make_pair
    #define pr pair<int,int>
    #define fi first
    #define sc second
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    const int M = 100005;
    const int INF = 1000000009;
    const double eps = 1e-7;
    
    int read()
    {
        int ans = 0,op = 1;char ch = getchar();
        while(ch < '0' || ch > '9') {if(ch == '-') op = -1;ch = getchar();}
        while(ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0',ch = getchar();
        return ans * op;
    }
    
    int a,b,c,d,k,p[M],mu[M],tot,sum[M],n;
    bool np[M];
    
    void euler()
    {
       np[1] = 1,mu[1] = 1;
       rep(i,2,M-2)
       {
          if(!np[i]) p[++tot] = i,mu[i] = -1;
          for(int j = 1;i * p[j] <= M-2;j++)
          {
         np[i * p[j]] = 1;
         if(!(i % p[j])) break;
         mu[i * p[j]] = -mu[i];
          }
       }
       rep(i,1,M-2) sum[i] = sum[i-1] + mu[i];
    }
    
    int solve(int a,int b)
    {
       a /= k,b /= k;
       int m = min(a,b),ans = 0;
       for(int i = 1,j;i <= m;i = j + 1)
       {
          j = min(a / (a / i),b / (b / i));
          ans += (a / i) * (b / i) * (sum[j] - sum[i-1]);
       }
       return ans;
    }
    
    int main()
    {
       euler();
       n = read();
       rep(i,1,n)
       {
          a = read(),b = read(),c = read(),d = read(),k = read();
          printf("%d
    ",solve(b,d) + solve(a-1,c-1) - solve(a-1,d) - solve(c-1,b));
       }
       return 0;
    }
    
    
  • 相关阅读:
    python运行出现TypeError: super() takes at least 1 argument (0 given)错误
    史上最全Python数据分析学习路径图
    Windows平台Python编程必会模块之pywin32
    PyMySQL的基本使用
    python:让源码更安全之将py编译成so
    最高分是多少
    哪些技术可以用在WEB开发中实现会话跟踪
    自定义输入模板
    JAVA中HashMap和Hashtable区别
    Java中ArrayList与LinkedList的区别
  • 原文地址:https://www.cnblogs.com/captain1/p/10122347.html
Copyright © 2011-2022 走看看