`
huobengluantiao8
  • 浏览: 1028607 次
文章分类
社区版块
存档分类
最新评论

HDU 1576 A/B 数论水题

 
阅读更多

来源:http://acm.hdu.edu.cn/showproblem.php?pid=1576

题意:中文题。。。

思路:设A = k * 9973 + n ,A/ B = C, C = P * 9973 + x,x即为我们所求的答案。易知,A = k* 9973 + n =B * P * 9973 + B * x,化简后得k * 9973 = B * P * 9973 + B * x - n,因此(B * x - n)%9973 = 0,n的值知道,B的值知道,又因为x的取值范围是0到9972,因此枚举x的值即可,满足条件的就是答案。

代码:

#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main(){
	int numcase;
	scanf("%d",&numcase);
	while(numcase--){
	  __int64 n,b;
	  int x;
	  scanf("%I64d%I64d",&n,&b);
	  for(int i = 0;i < 9973; ++i){
		  if(( b * i - n ) % 9973 == 0){
		    x = i;
			break;
		  }
	  }
	  printf("%d\n",x);
	}
	return 0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics