zoj 3435 莫比乌斯基础
来源:互联网 发布:java编写四级查分软件 编辑:程序博客网 时间:2024/05/23 12:51
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
Hint
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
在 方体 (a,b,c) 内 求过(1,1,1)的直线
全部-1 就变成(a-1,b-1,c-1) 和 0 0 0 就和上一题一样了,那么就是 求 一个点为0 两个点为0的情况
因为莫比乌斯求的是 大于等于1的情况,所以把两个为0的情况(只有3种加上就好)单独考虑上
有一个为0 那么,那么利用剩下不为0的两个进行莫比乌斯,加上三个不为0的莫比乌斯情况就好,因为gcd还是=1,所以所以枚举数量还是n/1(即全部)
数据量较大 达到了1e6 常数太大所以必须加速,
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e6+100; bool vis[maxn]; int prime[maxn],mu[maxn]; int cnt,sum[maxn]; void Init(){ int N=maxn; memset(prime,0,sizeof(prime)); memset(mu,0,sizeof(mu)); memset(vis,0,sizeof(vis)); mu[1] = 1; cnt = 0; for(int i=2; i<N; i++){ if(!vis[i]){ prime[cnt++] = i; mu[i] = -1; } for(int j=0; j<cnt&&i*prime[j]<N; j++){ vis[i*prime[j]] = 1; if(i%prime[j]) mu[i*prime[j]] = -mu[i]; else{ mu[i*prime[j]] = 0; break; } } } for(int i=1;i<N;i++) sum[i]=sum[i-1]+mu[i]; }ll cal(ll x1,ll x2){ ll gg=min(x1,x2); ll total=0; for(int i=1,next=0;i<=gg;i=next+1) { next=min(x1/(x1/i),x2/(x2/i)); total+=(sum[next]-sum[i-1])*((x1/i)*(x2/i)); } return total;}ll cal1(ll x1,ll x2,ll x3){ ll gg=min(min(x1,x2),x3); ll total=0; for(int i=1,next=0;i<=gg;i=next+1) { next=min(x1/(x1/i),min(x2/(x2/i),x3/(x3/i))); total+=(sum[next]-sum[i-1])*((x1/i)*(x2/i)*(x3/i)); } return total;}int main(){ ll x,y,z; Init(); while(scanf("%lld%lld%lld",&x,&y,&z)!=EOF) { x--,y--,z--; ll total=3; total+=cal(x,y); total+=cal(y,z); total+=cal(x,z); total+=cal1(x,y,z); cout<<total<<endl; }}
- zoj 3435 莫比乌斯基础
- ZOJ 3435 Ideal Puzzle Bobble (莫比乌斯反演基础题)
- 【莫比乌斯函数】【ZOJ 3435】Ideal Puzzle Bobble
- zoj 3435 spoj 7001 莫比乌斯反演
- spoj 7001 zoj 3435 莫比乌斯反演
- ZOJ 3868 GCD Expectation 莫比乌斯反演
- ZOJ 3868 GCD Expectation 莫比乌斯反演
- ZOJ 3824 Fiber-optic Network ~莫比乌斯
- ZOJ 3868 GCD Expectation(莫比乌斯反演)
- ZOJ 3435 Ideal Puzzle Bobble(gcd(i,j,k)=1/莫比乌斯反演)
- ZOJ 3435 Ideal Puzzle Bobble(莫比乌斯反演)
- 【数论-莫比乌斯】SPOJ-7001-Visible Lattice Points 、zoj 3435 Ideal Puzzle Bobble
- ZOJ 3868 GCD Expectation (容斥+莫比乌斯反演)
- 51nod 1240 莫比乌斯函数 【数论基础】
- hdu 1695 莫比乌斯基础题
- SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
- HDU 5212 Code (容斥 莫比乌斯反演基础题)
- 组合数学常用内容——基础内容+莫比乌斯反演
- 机器学习PAI教你如何品酒
- 激光雷达 imu 同步
- HDU 1754 I Hate it (树状数组)(区间最大值)
- 一个人的旅行
- 剔除除了自动编号不同,其他都相同的学生冗余信息
- zoj 3435 莫比乌斯基础
- bootstrap之datetimepicker(日期时间选择器)插件详细使用方法
- Oracle 地址
- E
- Resources Hook
- jQuery学习之内容过滤选择器、表单域选中选择器
- MYSQL索引分类介绍
- Hibernate学习笔记2
- Python初学之类的狭义属性(@property)