[ARC 102C]Triangular Relationship

Atcoder ARC 102C

C:Triangular Relationship

题意:

你有两个数\(N,K\),找到有多少三元组\((a,b,c)\),满足其中元素为\([1,n]\)的正整数,同时\(a+b\),\(b+c\),\(c+a\)都是\(K\)的倍数,其中\(a\),\(b\),\(c\)互换顺序算不同方案。
\(N,K \le 200000\)

题解:

因为\(a+b \equiv b+c \equiv c+a \pmod K\),所以\(a \equiv b \equiv c \pmod K\) 或者 \(a \equiv b \equiv c \pmod {\frac{K}{2}}\)
随便统计一下就行了

过程:

1A

代码:

int n,k;
ll ans;
inline ll Pow(ll a,int b) {return a*a*a;}
signed main() {
    read(n); read(k);
    int t=n/k;
    if(k&1) ans=Pow(t,3);
    else {
        ans=Pow(t,3);
        t=t+(n%k>=k/2 ? 1 : 0);
        // printf("%d\n",t);
        ans+=Pow(t,3);
    }
    printf("%lld\n",ans);
    return 0;
}

用时:10min

猜你喜欢

转载自www.cnblogs.com/functionendless/p/9574859.html
arc