小光棍数

来源:互联网 发布:平面设计怎么样知乎 编辑:程序博客网 时间:2024/05/17 06:34

小光棍数

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



原创粉丝点击