首页 > 技术文章 > uva 11029

avema 2013-11-04 21:58 原文

看了别人的解法 发现了 modf 这个函数 取小数部分

/*************************************************************************
    > Author: xlc2845       > Mail: xlc2845@gmail.com
    > Created Time: 2013年11月04日 星期一 16时15分37秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
#include <cstdlib>
#define maxn 300
#define LL long long
#define mod 1000
using namespace std;

int mymod(int a, int n)
{
	if (n == 0) return 1;
	int x = mymod(a, n/2);
	LL ans = (LL)x*(LL)x % (LL)mod;
	if (n%2) ans = ans*a % mod;
	return (int)ans;
}

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
	    int n,k;
	    double cc;
		scanf("%d%d", &n, &k);
		printf("%d...%03d\n", (int)pow(10.0, 2.0 + modf((double)k * log10(n), &cc)), mymod(n, k));
	}
	return 0;
}


推荐阅读