403 平方计数 思维+数论 [代码源][namomo spring camp]每日一题div1

题目链接
在这里插入图片描述

//acmer mxc
#include<bits/stdc++.h>
#define mst(s,x) memset(s,x,sizeof(s));
#define sr(x) scanf("%lld",&x); 
#define sr2(a,b) scanf("%d%d",&a,&b); 
#define sr3(a,b,c) scanf("%d%d%d",&a,&b,&c); 
#define sr4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d);
#define f(i,a,n) for(int i=a;i<=n;i++)
#define ff(i) for(int i=1;i<=n;i++)
#define sc(x) cout<<#x<<" : "<<x<<endl;
#define hh cout<<endl;
//#define int __int128
#define pii pair<int,int>
#define pb(x) push_back(x)
#define mk(a,b) make_pair(a,b)
#define ls(x) x<<1
#define rs(x) x<<1|1
#define fi first
#define se second
#define ll __int128
#define inf 0x3f3f3f3f
using namespace std;
inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') x=(x<<1)+(x<<3)+c-'0',c=getchar();
	return w==1?x:-x;
}
inline void write(ll x)
{
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
//------------------------------------------------
#define int long long
#define dd double
const int N=1e6+5;
int n;
int a[N];
inline void solve()
{
	cin>>n;
	ff(i)
	{
		int now;
		scanf("%lld",&now);
		a[now]++;
	}
	int ans=0;
	for(int i=1;i<=1e6;i++) //枚举因子
	{
		for(int j=i;j<=1e6;j+=i)  
		{
			if(!a[j])continue;
			int x=min(j/i,i);
			int y=max(j/i,i);
			if((y-x)&1)continue;
			ans+=a[j]*a[(y-x)/2];
		}
	}
	cout<<ans/2<<endl;
	return;
}

//------------------------------------------------
signed main()
{
	clock_t c1=clock();
#ifdef LOCAL
    freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif
//==================================
    int T=1;
	// cin>>T;
	for(int i=1;i<=T;i++)
	{
		solve();
	}
//==================================
end:
    cerr<< "Time used:" << clock() - c1 << endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

while WA er

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值