Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用构造的思想,递归解决

Posted by were at 2011-08-03 10:01:17 on Problem 2897
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator