QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#520#312194#8000. 平方数5ab5abSuccess!2024-01-23 17:03:112024-01-23 17:03:11

詳細信息

Extra Test:

Time Limit Exceeded

input:

300000
23768741896345550770650537601358310 7008780881790737660918902153322941 99144345908189152614206771911195141 45374013708515925852543924950694983 3926552137232556786616857884003803 42426896386025452115764224814743851 422464619353986377449490087140202641 3704482190798384114605520694663499 1486170...

output:


result:


ID题目提交者结果用时内存语言文件大小提交时间测评时间
#312194#8000. 平方数5ab97 1210ms41924kbC++202.4kb2024-01-23 16:22:412024-01-23 17:03:39

answer

// Author: Little09
// Problem: P10063 [SNOI2024] 平方数
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P10063
// Memory Limit: 1 MB
// Time Limit: 1500 ms
// Start Time: 2024-01-19 15:22:25
// 
// Powered by CP Editor (https://cpeditor.org)

#pragma GCC optimize("Ofast","unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937_64 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=5000005;
int n,m; 
i128 a[N];

i128 read()
{
	i128 res=0;
	char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9')
	{
		res=res*10+c-'0';
		c=getchar();
	}
	return res;
}
bool check(int x)
{
	rep(i,2,(int)sqrt(x))
	{
		if (x%i==0) return 0;
	}
	return 1;
}
vector<int>st;
void init()
{
	per(i,5000000,1)
	{
		if (check(i))
		{
			bool flag=0;
			rep(j,1,n) if (a[j]%i==0) flag=1;
			if (flag==0)
			{
				st.pb(i);
				if (SZ(st)==50) return;
			}
		}
	}
}
ull b[N],c[N];
bool v[N];
ll ans;
vector<int>q[N];
int id[N];


int main()
{
	cin >> n;
	rep(i,1,n) a[i]=read();
	init();
	rep(i,0,SZ(st)-1)
	{
		int p=st[i];
		rep(j,1,p-1) v[j]=0;
		rep(j,1,p-1) v[1ll*j*j%p]=1;
		rep(j,1,n)
		{
			int u=a[j]%p;
			if (v[u]==0) b[j]|=(1ull<<i);
		}
	}
	rep(i,1,n) b[i]^=b[i-1];
	rep(i,0,n) c[i]=b[i];
	stable_sort(c,c+n+1);
	rep(i,0,n) b[i]=lower_bound(c,c+n+1,b[i])-c;
	rep(i,0,n)
	{
		ans+=q[b[i]].size();
		id[i]=SZ(q[b[i]]);
		q[b[i]].pb(i);
	}
	cout << ans << "\n";
	int cnt=0;
	rep(i,0,n)
	{
		int l=SZ(q[b[i]]);
		rep(j,id[i]+1,l-1)
		{
			printf("%d %d\n",i+1,q[b[i]][j]);
			++cnt;
			if (cnt==100000) return 0;
		}
	}
	return 0;
}