#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long LL;
using namespace std;
LL X,n,r;
void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(b==0)
{
d=a;
x=1;
y=0;
}
else
{
exgcd(b,a%b,d,y,x);
y-=(a/b)*x;
}
}
LL res[100000],cnt;
void add(LL a,LL b)
{
LL c=2*r,d,x,y,t;
exgcd(a,b,d,x,y);
if(c%d==0)
{
x*=c/d,y*=c/d;
t=a/d;
for(int i=y%t;i*b-r<n;i+=t)
if(i*b-r>=0&&(i*b-r)*(i*b-r)%n==X)
res[cnt++]=i*b-r;
}
}
void solve()
{
cnt=1;
res[0]=r;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
add(i,n/i);
add(n/i,i);
}
}
sort(res,res+cnt);
cnt=unique(res,res+cnt)-res;
for(int i=0;i<cnt;i++)
printf(" %lld",res[i]);
printf("\n");
}
int main()
{
int t=1;
while(~scanf("%lld%lld%lld",&X,&n,&r)&&(n+X+r))
{
printf("Case %d:",t++);
solve();
}
}
LA 4270 离散平方根
最新推荐文章于 2019-08-01 19:05:31 发布