HDU 4342

View Code
 1 #include<iostream>
 2 #include<set>
 3 #include<cstdio>
 4 #include<cmath>
 5 using namespace std;
 6 typedef long long int ll;
 7 set<ll> S;
 8 
 9 void prepare()
10 {
11      ll end = ll(sqrt(double((1<<31) - 1)));
12      for (ll i(2); i<=end; ++i) {
13          S.insert(i*i);    
14      }
15      end = (1<<31) - 1;
16      ++end;
17      //cout<<end<<endl;
18      S.insert(end);   
19 }
20 
21 int main()
22 {
23     int t;
24     prepare();
25     scanf("%d",&t);
26     while (t--) {
27           ll n;
28           scanf("%I64d",&n);
29           if (n<3) {
30              cout<<n+1<<" "<<n+1<<endl;
31              continue;         
32           }
33           ll ans1(0),cnt(3);
34           for (set<ll>::iterator i = S.begin(); i != S.end(); ++i) {
35               set<ll>::iterator j = i;
36               ++j;
37               if (cnt <= n && n <= cnt + (*j - *i - 2)) {
38                   ans1 = n - cnt + 1 + *i;
39                   break;      
40               } else {
41                   cnt += (*j - *i - 1);
42               }    
43           }
44           
45           ll ans2(3);
46           cnt = 2;
47           for (set<ll>::iterator i = S.begin(); i != S.end(); ++i) {
48               set<ll>::iterator j = i;
49               ++j;
50               if (*i <= ans1 && ans1 <= *j) {
51                  ans2 += cnt*(ans1 - *i + 1);
52                  break;       
53               } else {
54                  ans2 += cnt*(*j - *i);
55                  ++cnt;       
56               }   
57           }
58           cout<<ans1<<" "<<ans2<<endl;
59     }
60     return 0;    
61 }
posted on 2012-08-09 19:13  Dev-T  阅读(159)  评论(0编辑  收藏  举报