zoukankan      html  css  js  c++  java
  • GCD(关于容斥原理)

    Problem Description
    Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're only required to output the total number of different number pairs.
    Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.

    Yoiu can assume that a = c = 1 in all test cases.
     
    Input
    The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 3,000 cases.
    Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
     
    Output
    For each test case, print the number of choices. Use the format in the example.
     
    Sample Input
    2 1 3 1 5 1 1 11014 1 14409 9
     
    Sample Output
    Case 1: 9 Case 2: 736427
     

    这个问题是用容斥原理来解决的,我们知道的是根据gcd(x,y)=k--> gcd(x/k,y/k)=1;

    这样子的话,我们当k为0的时候特判一下就行了,剩下的就是根据容斥原理来做了,已知区间[1,y]如何求z和区间里面的几个数互质。。。

    但是有一点我是真的不明白,为什么不超时啊,3000组数据的话,我真的不知道为什么不超时,求大神指点啊。

  • 相关阅读:
    docker入门——centos安装
    NET应用——你的数据安全有必要升级
    mysql事件机制——定时任务
    是时候升级你的Js工具了-分页【基于JQ】
    优美库图片系统
    爬虫之蜂鸟网图片爬取
    壁纸提取
    CSDN刷阅读数
    tkinter基础-输入框、文本框
    数据结构与算法之选择排序
  • 原文地址:https://www.cnblogs.com/Heilce/p/6405109.html
Copyright © 2011-2022 走看看