http://acm.hdu.edu.cn/showproblem.php?pid=1111
复数除法:
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int a[110]; 7 __int64 n; 8 int x1,y1,b1,b2; 9 int t1; 10 bool flag; 11 12 void dfs(int cnt) 13 { 14 if(cnt>100) return; 15 if(x1==0&&y1==0) 16 { 17 flag=true; 18 t1=cnt; 19 return; 20 } 21 for(int i=0; i*i<=n; i++) 22 { 23 if(flag) return; 24 __int64 xx=(x1-i)*b1+y1*b2; 25 __int64 yy=y1*b1-(x1-i)*b2; 26 if(xx%n==0&&yy%n==0) 27 { 28 x1=xx/n; 29 y1=yy/n; 30 a[cnt]=i; 31 dfs(cnt+1); 32 } 33 } 34 } 35 36 int main() 37 { 38 int t; 39 scanf("%d",&t); 40 while(t--) 41 { 42 scanf("%d%d%d%d",&x1,&y1,&b1,&b2); 43 n=b1*b1+b2*b2; 44 flag=false; 45 dfs(0); 46 if(!flag) 47 { 48 printf("The code cannot be decrypted. "); 49 } 50 else 51 { 52 printf("%d",a[t1-1]); 53 for(int i=t1-2; i>=0; i--) 54 { 55 printf(",%d",a[i]); 56 } 57 printf(" "); 58 } 59 } 60 return 0; 61 }