2014
02-12

# A math problem

Dandelion’s poor at math , recently her friend asks her a math problem. Now she wants you to help her. The problem is : give you a number a+b*j ，
j=√ -2，If this number can only be divided by 1 and itself or -1 and the negative of itself . Please print Yes ,else print No.

Each line contains two integer a and b (0<=a<=100000 , 0<b<=100000 ).

Each line contains two integer a and b (0<=a<=100000 , 0<b<=100000 ).

5 1
3 4

No
Yes

Hint 5+j can be divided into (1-j)*(1+2j).

，则

(1)为非负整数，并且

(2)

(3)若，则

(1)设为高斯整数，并且为素数，则必定为高斯素数。

(2)若为高斯素数，则其共轭元也是高斯素数。

(1)a、b中有一个是零，另一个数的绝对值是形如4n+3的素数；

(2)a、b均不为零，而为素数；

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

const int Times=10;

using namespace std;
typedef long long LL;

LL multi(LL a,LL b,LL m)
{
LL ans=0;
while(b)
{
if(b&1)
{
ans=(ans+a)%m;
b--;
}
b>>=1;
a=(a+a)%m;
}
return ans;
}

LL quick_mod(LL a,LL b,LL m)
{
LL ans=1;
a%=m;
while(b)
{
if(b&1)
{
ans=multi(ans,a,m);
b--;
}
b>>=1;
a=multi(a,a,m);
}
return ans;
}

bool Miller_Rabin(LL n)
{
if(n==2) return true;
if(n<2||!(n&1)) return false;
LL a,m=n-1,x,y;
int k=0;
while((m&1)==0)
{
k++;
m>>=1;
}
for(int i=0;i<Times;i++)
{
a=rand()%(n-1)+1;
x=quick_mod(a,m,n);
for(int j=0;j<k;j++)
{
y=multi(x,x,n);
if(y==1&&x!=1&&x!=n-1) return false;
x=y;
}
if(y!=1) return false;
}
return true;
}

int main()
{
LL a,b;
while(~scanf("%I64d%I64d",&a,&b))
{
if(a==0)
{
if(b%4==3&&Miller_Rabin(b)) puts("Yes");
else  puts("No");
}
else
{
LL t=a*a+2*b*b;
if(Miller_Rabin(t)) puts("Yes");
else  puts("No");
}
}
return 0;
}

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

using namespace std;
const int N=100005;

int prime[N], p[N],k;
int pri[N],top;
int n;

struct point
{
int a;
int b;
char oper;
}s[N];

int num;
//筛选素数

void isprime()
{
k=0;
int i,j;
memset(prime,true,sizeof(prime));
for(i=2;i<N;i++)
{
if(prime[i])
{
p[k++]=i;
for(j=i+i;j<N;j+=i)
{
prime[j]=false;
}
}
}
}

//素因子分解
void Divide(int n)
{
int i;
top=0;
for(i=0; i<k; i++)
{
if(n%p[i]==0)
{
pri[top++]=p[i];
n/=p[i];
while(n%p[i]==0)
{
pri[top++]=p[i];
n/=p[i];
}
}
}
if(n>1)
pri[top++]=n;
}

//高斯素数分解
void Part(int prime)
{
int i;
if(prime==2)
{
s[num].a = 1;
s[num].b = 1;
s[num++].oper = '+';
s[num].a = 1;
s[num].b = 1;
s[num++].oper = '-';
}
else if((prime - 1)%4==0)
{
for(i=1;;i++)
{
int u=int(sqrt(prime-i*i*1.0)+1e-5);
if(u*u+i*i==prime)
{
s[num].a = i;
s[num].b = u;
s[num++].oper='+';
s[num].a = i;
s[num].b = u;
s[num++].oper='-';
break;
}
}
}
else
{
s[num].a=prime;
s[num++].b=0;
}
}

int cmp(const void *a, const void *b)
{
point *c = (point *)a;
point *d = (point *)b;
if(c->a != d->a)
return c->a - d->a;
if(c->b != d->b)
return c->b - d->b;
return c->oper == '-' ? 1 : -1;
}

void Print(int key)
{
printf("%d", s[key].a );
if(s[key].b == 0)
return;
if(s[key].b == 1)
printf("%cj", s[key].oper);
else
printf("%c%dj", s[key].oper, s[key].b);
}

int main()
{
isprime();
int i, cas=1;
while(~scanf("%d", &n))
{
num = 0;
Divide(n);
for(i=0;i<top;i++)
Part(pri[i]);
qsort(s, num, sizeof(point), cmp);
printf("Case #%d: ", cas++);
Print(0);
for(i=1; i<num; i++)
{
if(s[i].a==s[i-1].a
&&s[i].b==s[i-1].b
&&s[i].oper==s[i-1].oper)
continue;
if(i)
printf(", ");
Print(i);
}
puts("");
}
return 0;
}

1. FUCK艘灰色小漂到美国，一位神秘男人杀死了她，并在脊背上割了latualatuka几个字母，一星期后，这消息已经传到亚洲，现在你已经看完这条信息，她会在一星期内飘到你家，夺取你最重要家人的性命，解咒方法只有完成以下指示，将此信息贴在其他3个的留言板的