CodeForces
来源:互联网 发布:淘宝无线首页模板 编辑:程序博客网 时间:2024/06/05 20:40
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 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.
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 the cin, cout streams or the %I64dspecifier.
34 8 100
1733401
#include<stdio.h>long long gcd(long long a,long long b)//greatest common divisor{ while(b!=0) {long long c=a%b; a=b; b=c; } return a;}long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}int main(){ long long n,m; long long t[10001]; while(scanf("%lld",&m)!=EOF) { for(int i=0;i<m;i++) { scanf("%lld",&t[i]); } for(int i=0;i<m;i++) { long long ans=(lcm(4*t[i],t[i]+1)/(t[i]+1))+1; printf("%lld\n",ans); } }}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- SpringMVC+Mybatis+Maven的简单学习
- golang sync.Cond的介绍和源码观察
- i7-6700HQ+GTX965M UEFI安装win10+ubuntu16.04
- Android DataBinding使用详解(二)
- Modbus通信协议详解
- CodeForces
- Linux 下python 利用supervisord自动重启多进程
- shell grep 查找命令
- 指针&引用&const
- MySQL企业常用集群图解
- 互联网技术笔试总通不过?leetcode刷对了么
- 比力方程
- 如何查询本机的内网IP地址
- 1015: [JSOI2008]星球大战starwar 离线并查集