小光棍数

小光棍数

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 1
描述
最近Topcoder的XD遇到了一个难题,倘若一个数的三次方的后三位是111,他把这样的数称为小光棍数。他已经知道了第一个小光棍数是471,471的三次方是104487111,现在他想知道第m(m<=10000000000)个小光棍数是多少?
输入
有多组测试数据。第一行一个整数n,表示有n组测试数据。接下来的每行有一个整数m。
输出
输出第m个小光棍数。
样例输入
1
1
样例输出
471
来源
原创
上传者

wmnwmn


问题分析:m<=10000000000  m太大了,超过了int型最大,还得用long long来存储。用数组筛选出m以内的所有光棍数也不可能,因为光建立数组就超过了限制内存大小。只能另辟蹊径,最后在网上发行其实光棍数的后 三位都是471.

代码:

#include <iostream>  
#include <stdio.h>   
#include <string.h>  
#include <math.h>  
#include <vector>  
#include <queue>  
#include <stack>  
#include <map>  
#include <string>  
#include <algorithm>  
#include <iomanip>
#define MAX 10000000000
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	/*freopen("file/input.txt","r",stdin);
	freopen("file/output.txt","w",stdout);*/
	int n;
	scanf("%d",&n);
	while(n--){
		long long tmp;
		scanf("%lld",&tmp);
		printf("%lld\n",(tmp-1)*1000+471);
	}
	
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值