hdu2650

A math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 233    Accepted Submission(s): 112


Problem Description
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.
 

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

Output
Yes or No for each case.
 

Sample Input
5 1 3 4
 

Sample Output
No Yes Hint 5+j can be divided into (1-j)*(1+2j).
AC代码:
#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; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值