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

请大牛解释一下~为什么用g++ long long就RUNTIME ERROR, c++ __int64 就AC, 如果比赛碰到这种问题,还不栽了.....

Posted by cannie at 2005-10-18 23:47:00 on Problem 2514
#include <stdio.h>
#include <math.h>
long long finda(long long k){
	char s[30];
	long long tot, i, res, m;
	int d[30] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
				 100000000, 1000000000};
	tot = 0;
	for (i = 1;; i++){
		if (tot + i * (d[i+1] - d[i]) >= k)
			break;
		tot += i * (d[i+1] - d[i]);
	}
	res = k - tot;
	m = (res - 1) % i;
	res = (res - 1) / i;
	res += d[i];
	sprintf(s, "%lld", res);
	return s[m] - '0';
}
long long findb(long long k){
	char s[30];
	long long tot, i, res, m;
	int d[30] = {0, 1, 4, 10, 32, 100, 317, 1000, 3163, 10000, 31623,
				 100000, 316228, 1000000, 3162278, 10000000, 31622777,
				 100000000, 316227767, 1000000000};
	tot = 0;
	for (i = 1;; i++){
		if (tot + i * (d[i+1] - d[i]) >= k)
			break;
		tot += i * (d[i+1] - d[i]);
	}
	res = k - tot;
	m = (res - 1) % i;
	res = (res - 1) / i;
	res += d[i];
	sprintf(s, "%lld", res * res);
	return s[m] - '0';
}
int main(){
	long long k, res, tmp;
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	while (scanf("%lld", &k) == 1 && k > 0){
		res = finda(k) + findb(k);
		k++;
		tmp = finda(k) + findb(k);
		while (tmp == 9){
			k++;
			tmp = finda(k) + findb(k);
		}
		if (tmp > 9)
			res ++;
		printf("%lld\n", res % 10);
	}
}

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