zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 86 (Rated for Div. 2) C. Yet Another Counting Problem

    https://codeforces.com/contest/1342/problem/C

     

     

    题意:给定的区间【L,R】中有多少个数可以满足mod amod ≠ mod mod )。

    题解:暴力打表,n = a * b ,扫描1-n之间有多少数满足mod amod ≠ mod mod ) ,并记录下来。然后计算( R/n - (L-1)/n )*num[n] + num[R%n] - num[(L-1)%n] , 为什么是 L -1 呢, 是因为,x / n + num[ x % n] 计算的是x为终点的符合题意的数,而 L是包含在计算的区间内的,所以就要就算L-1区间

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <list>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <iomanip>
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define mem(sum,x) memset(sum,x,sizeof(sum))
    #define rep(i,start,end) for(int i=start;i<=end;i++)
    #define per(i,end,start) for(int i=end;i>=start;i--)
    #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    using namespace std;
    const int mod = 1e9+7 ;
    const int mxn = 1e6+7 ;
    ull _,n,m,k,t,u,v,w,ans,cnt,ok;
    int a[mxn] , num[mxn] , pre[mxn] , last[mxn] ;
    int main()
    {
        ull l , r , x ;
        int a, b ,q ;
        for(cin>>t;t;t--)
        {
            cin>>a>>b>>q;
            n = a*b;
            for(int i=1;i<=n;i++)
            {
                num[i]=num[i-1];
                if(i%a%b!=i%b%a) num[i]++;
            }
            while(q--)
            {
                cin>>l>>r;
                cout<<( r/n - (l-1)/n )*num[n] + num[r%n] - num[(l-1)%n]<<endl;
            }
        }
    }
     
    所遇皆星河
  • 相关阅读:
    python_day10 socket serverr
    python_day10 协程 GEVENT
    python_day10 协程 Greenlet
    python_day10 协程
    python_day10 paramiko模块
    python-day10 线程 queue
    python_day10 event
    python_day10 信号量
    python_day10 锁
    CSS命名规范(规则)
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12784871.html
Copyright © 2011-2022 走看看