HNU2019 Summer Training 3 B. Broken Watch

Problem Description

A UFO crash lands on Earth. The alien captain survives the crash relatively unscathed; however his trusty watch is damaged beyond repair.

The alien watch is very similar to a human watch: It is a disc 30mm in diameter and it has three hands of lengths A, B and C microns (1000 ≤ A, B, C ≤ 15000). However, the aliens measure time differently: there are N(2≤N&lt;232)N (2 ≤ N &lt; 2^{32})N(2N<232) alien seconds to an alien minute. As such, there are N markings on the edge of the disc, rather than 60.

The watch’s glass cover is broken and the hands have come loose: they can rotate freely and independently of one another. By pointing each of the hands at an arbitrary marking, their tips can be made to form an imaginary triangle (as long as they are non-collinear).

Having nothing left to do but wait for help to arrive, the alien ponders the following question: What is the number M of distinct triangles that contain the watch’s center? (Triangles where the center lies on one of the edges of the triangle count as well.)

Input

The input consists of A, B, C, and N on a single line, separated by whitespace.

Output

The output is M modulo 2642^{64}264.

Sample Input

15000 15000 15000 2
5000 10000 15000 3
15000 15000 15000 3
15000 15000 15000 4
15000 15000 15000 5
15000 15000 15000 6

Sample Output

0
6
1
4
5
14

由于模的是2^64,完全可以不用理会,用unsigned long long即可,溢出了也不用理会,能保证答案正确,一开始由于多算了很多重复的情况,WA了一发
以为是“溢出取模法”不正确(其实是代码错了),改用java写一样wa
后修改了代码顺利AC

/*
 * Copyright (c) 2019 Ng Kimbing, HNU, All rights reserved. May not be used, modified, or copied without permission.
 * @Author: Ng Kimbing, HNU.
 * @LastModified:2019-07-28 T 14:40:37.721 +08:00
 */

import java.math.BigInteger;

import static ACMProblems.ACMIO.*;

public class Main {
    private static BigInteger MOD = new BigInteger("2").pow(64);
    private static BigInteger one = new BigInteger("1");
    private static BigInteger two = new BigInteger("2");
    private static BigInteger six = new BigInteger("6");

    public static void main(String[] args) throws Exception {
        while (true) {
            try {
                long a = nextLong();
                long b = nextLong();
                long c = nextLong();
                long n = nextLong();
                BigInteger bn = new BigInteger(Long.toString(n));
                BigInteger fact = one;
                if (a == b && a == c) {
                    fact = six;
                } else if (a == b || a == c || b == c) {
                    fact = two;
                }
                if (n % 2 == 0) {
                    BigInteger nSecond = bn.divide(two);
                    BigInteger ans = bn.multiply(nSecond.subtract(one).multiply(nSecond.add(two)).add(bn.subtract(two))).divide(fact).mod(MOD);
                    out.println(ans);
                } else {
                    BigInteger nSecond = bn.divide(two);
                    BigInteger ans = bn.multiply(nSecond).multiply(nSecond.add(one)).divide(fact).mod(MOD);
                    out.println(ans);
                }
                out.flush();
            } catch (Exception e) {
                out.flush();
                return;
            }
        }
    }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值