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 }

转载于:https://www.cnblogs.com/devtang/archive/2012/08/09/2630787.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值