zoukankan      html  css  js  c++  java
  • ABC108C

    题意

    给出$n, k$,求出满足$a+b, b + c, c + a$都是$k$的倍数的三元组$a, b, c$的个数,$1 leqslant a, b, c leqslant N$

    $n leqslant 10^5$

    Sol

    昨晚Atcoder的第三题

    我用$O(1)$的算法过了一个$n leqslant 10^5$的题qwq。

    首先当$a, b, c$是$k$的倍数的话肯定是满足条件的,答案为$(frac{N}{K})^3$

    关键是$a, b, c$中存在不是$k$的倍数的数,显然,此时$a, b, c$都不能是$k$的倍数

    打表找规律得,此时$a, b, c$可以为$frac{K}{2} + x*K$中的任意数

    然后就做完了。。。

    /*
     
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<vector>
    #include<set>
    #include<queue>
    #include<cmath>
    //#include<ext/pb_ds/assoc_container.hpp>
    //#include<ext/pb_ds/hash_policy.hpp>
    #define Pair pair<int, int>
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    #define int long long 
    #define LL long long 
    #define ull long long 
    #define rg register 
    #define pt(x) printf("%d ", x);
    //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 22)], *p1 = buf, *p2 = buf;
    //char obuf[1<<24], *O = obuf;
    //void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
    //#define OS  *O++ = ' ';
    using namespace std;
    //using namespace __gnu_pbds;
    const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
    const double eps = 1e-9;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    ull N, K;
    main() {
        //freopen("a.in", "r", stdin);
        //freopen("c.out", "w", stdout);
        N = read(); K = read();
        ull base = N / K;
        ull ans = base * base * base, ans2 = 0;
        if(K % 2 == 0) {
            base = (N - K / 2) / K + (N >= K / 2);
            ans2 += base * base * base;        
        }
        cout << ans + ans2;
        return 0;
    }
    /*
    50 12
    */
  • 相关阅读:
    Linux上面执行 Windows 命令(比如 重启服务)的简单方法
    Linux 通过cksum 来判断文件是否是相同
    Linux 根据端口快速停止服务并启动的办法
    Delphi控件开发浅入深出(三)
    Delphi 资源文件( .res)
    C++中模块(Dll)对外暴露接口的方式
    delphi Align属性
    cport串口控件的应用
    两款工控控件对比评测:Iocomp和ProEssentials
    Android 将ARGB图片转换为灰度图
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9572649.html
Copyright © 2011-2022 走看看