hdu6053 TrickGCD 莫比乌斯反演

2024-09-09 06:48

本文主要是介绍hdu6053 TrickGCD 莫比乌斯反演,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

TrickGCD

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Problem Description
You are given an array  A  , and Zhu wants to know there are how many different array  B  satisfy the following conditions?

1BiAi
* For each pair( l , r ) ( 1lrn ) ,  gcd(bl,bl+1...br)2

Input
The first line is an integer T( 1T10 ) describe the number of test cases.

Each test case begins with an integer number n describe the size of array  A .

Then a line contains  n  numbers describe each element of  A

You can assume that  1n,Ai105

Output
For the  k th test case , first output "Case #k: " , then output an integer as answer in a single line . because the answer may be large , so you are only need to output answer  mod   109+7

Sample Input
  
1 4 4 4 4 4

Sample Output
  
Case #1: 17

Source
2017 Multi-University Training Contest - Team 2

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;public class Main {public static void main(String[] args) {new Task().solve();}
}class Task {InputReader in = new InputReader(System.in) ;PrintWriter out = new PrintWriter(System.out) ;final long Mod = 1000000007L ;final int N = 100000 ;int[] mu = new int[N+1] ;int[] prime = new int[N+1] ;boolean[] vis = new boolean[N+1] ;{int cnt = 0 ;Arrays.fill(vis, false);mu[1] = 1 ;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]] = true ;if(i % prime[j] == 0){mu[i * prime[j]] = 0 ;break ; }mu[i * prime[j]] = -mu[i] ;}}}long pow(long x , int y){long s = 1 ;for(; y > 0 ; y >>= 1){if((y & 1) > 0){s *= x ;s %= Mod ;}x *= x ;x %= Mod ;}return s ;}void solve(){int t = in.nextInt() ; for(int cas = 1 ; cas <= t ; cas++){int[] sum = new int[2*N+1] ;int _min = Integer.MAX_VALUE ;int _max = Integer.MIN_VALUE ;long all = 1 ;Arrays.fill(sum, 0) ;int n = in.nextInt() ;int[] a = new int[n+1] ;for(int i = 1 ; i <= n ; i++){a[i] = in.nextInt() ;_min = Math.min(_min , a[i]) ;_max = Math.max(_max, a[i]) ;sum[a[i]]++ ;all *= a[i] ;all %= Mod ;}for(int i = 1 ; i <= 2*N ; i++){sum[i] += sum[i-1] ;}long _all = 0 ;for(int d = 1 ; d <= _min ; d++){long h = (mu[d] + Mod) % Mod ;for(int g = 1 ; g <= _max/d ; g++){int cnt = sum[d*(g+1)-1] - sum[d*g-1] ;h *= pow(g, cnt) ;h %= Mod ;}_all += h ;_all %= Mod ;}all -= _all ;all %= Mod ;all = (all + Mod) % Mod ;out.println("Case #"+ cas + ": " + all) ;}out.flush() ;}}class InputReader {    public BufferedReader reader;    public StringTokenizer tokenizer;    public InputReader(InputStream stream) {    reader = new BufferedReader(new InputStreamReader(stream), 32768);    tokenizer = new StringTokenizer("");    }    private void eat(String s) {    tokenizer = new StringTokenizer(s);    }    public String nextLine() {     try {    return reader.readLine();    } catch (Exception e) {    return null;    }    }    public boolean hasNext() {    while (!tokenizer.hasMoreTokens()) {    String s = nextLine();    if (s == null)    return false;    eat(s);    }    return true;    }    public String next() {    hasNext();    return tokenizer.nextToken();    }    public int nextInt() {    return Integer.parseInt(next());    }    public int[] nextInts(int n) {    int[] nums = new int[n];    for (int i = 0; i < n; i++) {    nums[i] = nextInt();    }    return nums;    }    public long nextLong() {    return Long.parseLong(next());    }    public double nextDouble() {    return Double.parseDouble(next());    }    public BigInteger nextBigInteger() {    return new BigInteger(next());    }    }    



这篇关于hdu6053 TrickGCD 莫比乌斯反演的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1150453

相关文章

学习笔记 ---- 莫比乌斯反演总结

文章目录 概述前置知识数论分块狄利克雷卷积积性函数 莫比乌斯函数定义性质 莫比乌斯反演因子形式倍数形式 例题周期性字符串互质数对[NOI2010D1T1]能量采集BZOJ2820 YY的GCD[SDOI2015] 约数个数和BZOJ4407 于神之怒加强版【BZOJ2693】jzptab最小公倍数之和[bzoj3529-Sdoi2014] 数表 练习题51nod 1675 序列变换BZOJ3

BZOJ 2440 2301 莫比乌斯应用

http://www.lydsy.com/JudgeOnline/problem.php?id=2440 Description 小 X 自幼就很喜欢数。但奇怪的是,他十分讨厌完全平方数。他觉得这些 数看起来很令人难受。由此,他也讨厌所有是完全平方数的正整数倍的数。然而 这丝毫不影响他对其他数的热爱。  这天是小X的生日,小 W 想送一个数给他作为生日礼物。当然他不能送一 个小X讨厌

莫比乌斯反演 两种形式

莫比乌斯反演在数论中占有重要的地位,许多情况下能大大简化运算。那么我们先来认识莫比乌斯反演公式。   定理:和是定义在非负整数集合上的两个函数,并且满足条件,那么我们得到结论           在上面的公式中有一个函数,它的定义如下:       (1)若,那么     (2)若,均为互异素数,那么     (3)其它情况下     对于函数

CodeForces 547C. Mike and Foam 莫比乌斯反演

题意:给定一个长度为n的数列a,和q个操作(1<= n,q <= 2*10^5, 1 <= a[i] <= 5*10^5 ) 需要维护一个多重集合Q. 每个操作给出一个下标i,如果a[i]属于Q那么把a[i]从Q中拿走,如果a[i]不属于Q,那么把a[i]加入Q中。 每次操作后询问Q中,有多少对i,j满足条件 i<j 且 gcd(a[i],a[j])=1 这个性质的维护比较困难,直

Python星载气溶胶数据处理与反演分析

在当前全球气候变化和环境污染问题日益突出的背景下,气溶胶研究显得尤为重要。气溶胶在大气中由直径范围在0.01微米至10微米固体和液体颗粒构成,直接或间接影响地球辐射平衡、气候变化和空气质量。尤其在“碳中和”目标的驱动下,研究气溶胶对“碳中和”的气候影响及其环境效应,不仅对科学研究具有重大意义,同时也为政策制定提供了重要依据。 MODIS(中分辨率成像光谱仪)和CALIOP(云-气溶胶偏振激光雷达

基于Python星载气溶胶数据处理与反演分析

原文链接:基于Python星载气溶胶数据处理与反演分析https://mp.weixin.qq.com/s?__biz=MzUzNTczMDMxMg==&mid=2247606689&idx=1&sn=bcdca97812e5e21e1bf539eafa49a48b&chksm=fa826046cdf5e95059f4ebc5ae6120b8e909883dd1d7c0eb4a5897e79df1

HDU 1695 GCD 容斥原理/莫比乌斯反演

题意: 给你两个区间[a,b],[c,d],还有一个k。让你从区间[a,b]中找出x,[c,d]中找出y,问共有多少组(x,y)使得gcd(x,y)=k。 (x,y)和(y,x)算一组。 思路: 参考:http://blog.csdn.net/yang_7_46/article/details/9072533 容斥。 普通容斥: *如果gcd(x,y)=k,则gcd(x/k

SPOJ 7001 Visible Lattice Points(莫比乌斯反演)

莫比乌斯反演,注意0的情况特殊考虑下就可以了 #include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1000005;int mo[N], prime[N], pn;bool vis[N];void Moblus() {memset(vis, false, siz

精密单点定位(PPP)数据处理反演潮汐(四)

前段时间,我又尝试用TerraPos处理一下SeaPath330的原始姿态和定位数据,看看反演潮位的效果如何。 首先,怎么预处理SeaPath330的定位和姿态数据, 记录格式如下1901200054.l09和1901200054.l10,咨询了SeaPath330的技术张工,对话如下: 张工,有个问题咨询一下,Seapath记录的RTCM数据格式.l09和IMU原始数据.l10怎么转成ri

【高校科研前沿】华东师大白开旭教授博士研究生李珂为一作在RSE发表团队最新成果:基于波谱特征优化的全球大气甲烷智能反演技术

文章简介 论文名称:Developing unbiased estimation of atmospheric methane via machine learning and multiobjective programming based on TROPOMI and GOSAT data(基于TROPOMI和GOSAT数据,通过机器学习和多目标规划实现大气甲烷的无偏估计) 第一作者及