Light OJ 1008

 

 

 

找规律。

  首先令n=sqrt(s),上取整。讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的。

 

Sample Input
3
8
20
25
Sample Output
Case 1: 2 3
Case 2: 5 4
Case 3: 1 5

 

*****************************************************

 

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 #include <algorithm>
 5 #include <math.h>
 6 #include <vector>
 7 using namespace std;
 8 typedef long long LL;
 9 const int INF = 0xfffffff;
10 const int maxn = 42000;
11 #define max(a,b)(a>b?a:b)
12 #define min(a,b)(a<b?a:b)
13 #define lson rt<<1
14 #define rson rt<<1|1
15 
16 int main()
17 {
18     int T,k=1;
19     long long s,n,a,x,y;
20 
21     scanf("%d", &T);
22 
23     while(T--)
24     {
25         scanf("%lld", &s);
26 
27         n=ceil(sqrt(double(s)));
28 
29         a=n*n-s;
30         if(a<n)
31         {
32             x=n;
33             y=a+1;
34         }
35         else
36         {
37             x=-n*n+2*n+s-1;
38             y=n;
39         }
40 
41         if(n%2!=0)swap(x,y);
42 
43         printf("Case %d: %lld %lld\n",k++,x,y);
44     }
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/weiyuan/p/5753530.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值