Circle Perimeter

Circle Perimeter

Problem

Given an integer r, find the number of lattice points that have a Euclidean distance from (0,0)
greater than or equal to r but strictly less than r+1.

A lattice point is a point with integer coordinates. The Euclidean distance from (0,0) to the point (x,y) is x 2 + y 2 x_2+y_2 x2+y2的平方根.

Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1000 ) (1≤t≤1000) (1t1000) — the number of test cases.

The only line of each test case contains a single integer r r r ( 1 ≤ r ≤ 1 0 5 ) (1≤r≤10^5) (1r105).

The sum of r over all test cases does not exceed 1 0 5 10^5 105.

Output

For each test case, output a single integer — the number of lattice points that have an Euclidean distance d from (0,0) such that r ≤ d < r + 1 r≤d<r+1 rd<r+1.

Example

Input
6
1
2
3
4
5
1984
Output
8
16
20
24
40
12504

Note

The points for the first three test cases are shown below.
在这里插入图片描述

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll t;
    cin>>t;

    while(t--)
    {
        ll r;
        cin>>r;
        
        ll y=r,d=0;
        for(ll x=0;x<=r;x++)//枚举横坐标x,寻找y满足条件
        {
            while(x*x+y*y>=(r+1)*(r+1)) y--;

            ll dy=y;
            while(dy>0&&x*x+dy*dy>=r*r)
            {
                d++;
                dy--;
            }
        }
        
        cout<<d*4<<endl;//四个方向
    }
    
    return 0;
}
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值