Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用构造的思想,递归解决#include <cstdio> #include <cstdlib> #include <cstring> int t,N,K,flag; void work(int a,int b,int p){ int ans = a*b+p; if(a==K && !p && flag) return; flag = 1; work(ans%10,b,ans/10); if(!flag) printf("%d",ans%10); else flag = 0; } int main(){ for(scanf("%d",&t);t--;){ scanf("%d%d",&N,&K); if(N>K) puts("0"); else work(K,N,0),printf("%d\n",K,N*K); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator