【lightoj1008】数学找规律

绝地灬酷狼 2022-07-17 00:27 284阅读 0赞

C - C 使用long long

Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu

Submit Status Practice LightOJ 1008 12x12_uDebug.pnguDebug

Description

Fibsieve had a fantabulous (yes, it’s an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.

678a248abb16e664b728836e149deaa8

(The numbers in the grids stand for the time when the corresponding cell lights up)

In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.

Output

For each case you have to print the case number and two numbers (x, y), the column and the row number.

Sample Input

3

8

20

25

Sample Output

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5

找规律并完美表达,注意细节,写的时候别着急。

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define LL long long
  6. using namespace std;
  7. int main() {
  8. int T,p=0;
  9. scanf("%d",&T);
  10. while(T--) {
  11. LL n;
  12. scanf("%lld",&n);
  13. LL cnt=sqrt(n);
  14. LL ant=n-cnt*cnt;
  15. LL temp=(cnt+1)*(cnt+1)-cnt*cnt;
  16. // printf("%lld %lld--\n",cnt,ant);
  17. printf("Case %d: ",++p);
  18. if(ant==0) {
  19. if((cnt*cnt)&1) {
  20. printf("1 %lld\n",cnt);
  21. // printf("==\n");
  22. } else {
  23. printf("%lld 1\n",cnt);
  24. }
  25. } else {
  26. if((cnt*cnt)&1) {
  27. if(ant<=temp/2) {
  28. printf("%lld %lld\n",ant,cnt+1);
  29. } else {
  30. printf("%lld %lld\n",cnt+1,temp-ant+1);
  31. }
  32. } else {
  33. if(ant<=temp/2) {
  34. printf("%lld %lld\n",cnt+1,ant);
  35. } else {
  36. printf("%lld %lld\n",temp-ant+1,cnt+1);
  37. }
  38. }
  39. }
  40. }
  41. return 0;
  42. }

发表评论

表情:
评论列表 (有 0 条评论,284人围观)

还没有评论,来说两句吧...

相关阅读