博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
<cf>Square
阅读量:5889 次
发布时间:2019-06-19

本文共 2381 字,大约阅读时间需要 7 分钟。

B. Square
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (n + 1) meters, he draws a cross (see picture for clarifications).

John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?

The figure shows the order in which John draws crosses for a square with side 4. The lower left square has two crosses. Overall John paints 17crosses.

Input

The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.

The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.

Output

For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use thecincout streams or the %I64d specifier.

Sample test(s)
input
34 8 100
output
1733401
思路:援引自

Problem «Square»

Let the pencil move by the line and put crosses through every (n + 1) point. Lets associate every point on the line with point on square perimeter. Namely, point x on the line will be associated with point on square perimeter that we will reach if we move pencil around square to x clockwise. Then lower left corner will be associated with all points 4np for every non-negative integer p. Crosses will be associated with points k(n + 1) for some non-negative k. Nearest point of overlap of two families of points will be in point LCM(n + 14n). Then we will put  crosses.

AC code:

#include 
using namespace std;int main(){ int T; long long n; cin>>T; while(T--) { cin>>n; long long a=4*n,b=n+1,r=a%b; while(r) { a=b; b=r; r=a%b; } long long cross=4*n/b+1; cout<
<

转载地址:http://bpysx.baihongyu.com/

你可能感兴趣的文章
gitlab 完整部署实例
查看>>
GNS关于IPS&ASA&PIX&Junos的配置
查看>>
影响企业信息化成败的几点因素
查看>>
SCCM 2016 配置管理系列(Part8)
查看>>
struts中的xwork源码下载地址
查看>>
ABP理论学习之仓储
查看>>
我的友情链接
查看>>
CentOS图形界面和命令行切换
查看>>
HTML5通信机制与html5地理信息定位(gps)
查看>>
加快ALTER TABLE 操作速度
查看>>
PHP 程序员的技术成长规划
查看>>
python基础教程_学习笔记19:标准库:一些最爱——集合、堆和双端队列
查看>>
js replace,正则截取字符串内容
查看>>
作业2
查看>>
nginx的信号量
查看>>
云im php,网易云IM
查看>>
DEFERRED_SEGMENT_CREATION
查看>>
Ada boost学习
查看>>
开源 java CMS - FreeCMS2.3字典管理
查看>>
block,inline和inline-block概念和区别
查看>>