标签:
input | output |
---|---|
2 |
5 |
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=2e5+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t,p[maxn],now[maxn]; vi mo[maxn]; int find(int x) { return p[x]==x?x:p[x]=find(p[x]); } int main() { int i,j; scanf("%d",&k); rep(i,1,maxn-10)p[i]=i; for(i=1;;i++) { ll q=((ll)i*i/k+1)*k; while((j=q-(ll)i*i)<i) { int x=find(j),y=find(i); if(x==y)return 0*printf("%d\n",i); else p[x]=y; now[j]=i; q+=k; } q=(ll)(i/k+1)*k; for(int x:mo[(q-i)%k]) { if(now[x]==i)continue; int y=find(x),r=find(i); if(y==r)return 0*printf("%d\n",i); else p[y]=r; } mo[(ll)i*i%k].pb(i); } //system("Pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5851638.html