3 solutions

  • 1
    @ 2026-5-27 17:41:57

    #define int long long #define endl '\n' using namespace std; int n,t,a[1000000]; map<int,int> c; signed main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n; c.clear(); for(int i=1;i<=n;i++){ cin>>a[i]; } vector s,b; for(int i=1;i<=n;i++){ b.clear(); if(a[i]<=10000){ c[a[i]]=1; b.push_back(a[i]); } for(auto v:s){ int l=v*a[i]/__gcd(v,a[i]); if(l>10000)break; c[l]=1; if(b.empty()||b.back()!=1)b.push_back(l); } s.swap(b); } int ans=1; while(ans<=10000&&c[ans])ans++; cout<<ans<<endl; }

    return 0;
    

    }

    • 0
      @ 2025-10-14 15:07:42

      幽默数

      容易发现,在左端点固定的时候,若右端点向右移动,则区间的 lcm \text{lcm} 值要么不变,要么至少乘以 22。而对于一个质数,它不可能成为任意两个与它不等的数的 lcm \text{lcm} ,而第 3×105+1 3 \times 10^5 + 1 个质数是 42562334256233,所以在所有区间的 lcm \text{lcm} 中,那些大于 42562334256233 的是没有用的。

      因此,记 V=4256233 V = 4256233 ,则当左端点固定的时候,不同的有用 lcm \text{lcm} 只有 logV \log V 个。

      考虑从右向左移动左端点,并且维护以当前点为左端点的不同 lcm \text{lcm} 。具体地,可以用两个集合 A,B A, B 分别维护当前存在的不同 lcm \text{lcm} 和所有可能有用的 lcm \text{lcm} 。左端点左移到 i i 的时候,需要将 ai a_i 放入 A A ,并遍历 A A 中本来就存在的区间,对 ai a_i lcm \text{lcm} 后重新放入 A A 。每次更新完之后,就把当前 A A 中的元素放入 B B 中。最后对 B B 中的元素求 mex \text{mex} 即可。

      时间复杂度 O(nlog2V)O(n \log^2 V)

      • -1
        @ 2026-5-27 17:08:43
        #define int long long
        #define endl '\n'
        using namespace std;
        int n,t,a[1000000];
        map<int,int> c;
        signed main(){
        	ios::sync_with_stdio(0);
        	cin.tie(0),cout.tie(0);
        	cin>>t;
        	while(t--){
        		cin>>n;
        		c.clear();
        		for(int i=1;i<=n;i++){
        			cin>>a[i];
        		}
        		vector<int> s,b;
        		for(int i=1;i<=n;i++){
        			b.clear();
        			if(a[i]<=10000){
        				c[a[i]]=1;
        				b.push_back(a[i]);
        			}
        			for(auto v:s){
        				int l=v*a[i]/__gcd(v,a[i]);
        				if(l>10000)break;
        				c[l]=1;
        				if(b.empty()||b.back()!=1)b.push_back(l);
        			}
        			s.swap(b);
        		}
        		int ans=1;
        		while(ans<=10000&&c[ans])ans++;
        		cout<<ans<<endl;
        	}
        	
        	return 0;
        }
        
        
        • 1

        Information

        ID
        1596
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        10
        Tags
        (None)
        # Submissions
        44
        Accepted
        1
        Uploaded By