<cf>Square

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
3
4 8 100
output
17
33
401
思路:援引自 http://codeforces.com/blog/entry/4673

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 <iostream>
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<<cross<<endl;
    }
    return 0;
}


<template> <view class="content"> <view class="padding-lr padding-top-sm bg flex" @click.stop="goSearch"> <view class="flex justify-between margin-right-sm" @tap.stop="getPlace" style="line-height: 68rpx;"> <!-- <u-image src="../../static/images/index/place.png" width="27rpx" height="37rpx"class="margin-top-xs" ></u-image> --> <view class="localName text-white margin-left-sm">西安市</view> </view> <u-search placeholder="搜大神" v-model="keyword" shape="square" disabled :show-action="false" :animation="true" bg-color="#343546"></u-search> </view> <scroll-view scroll-x class="bg nav text-white"> <view class="flex text-center"> <view class="cu-item flex-sub" :class="index==TabCur?'text-orange cur':''" v-for="(item,index) in tabData" :key="index" :data-id="index" @click=""> {{item.title}} </view> </view> </scroll-view> <view> <view class="wrap padding-sm"> <u-swiper :list="swiperList"></u-swiper> </view> <view class="" style="color: #BFBFCB;"> <u-grid :col="5" :border="false"> <u-grid-item bg-color="#111224" v-for="(item,index) in gridData" @tap="goNav(item)"> <u-image :src="item.image" mode="" width='92' height="92"></u-image> <view class="grid-text margin-top-sm">{{item.title}}</view> </u-grid-item> </u-grid> </view> <view class="bg margin-lr-sm padding-sm radius"> <view class="flex justify-between text-white padding-bottom-sm"> <view>乐享低价</view> <view>更多<u-image class="margin-left-sm" style="display: inline-block;" width="14upx" height="24upx" src="../../static/images/index/right.png"></u-image> </view> </view> <view class="flex justify-between"> <view @click="goOrder"> <view class="u-relative"> <u-image width="200upx" height="200upx" :src="src"></u-image> <view class="u-abso" style="bottom: 0;left: 0;color: white;background: rgba(0,0,0,.4);padding: 0 5upx;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 在线中 </view> </view> <view class="margin-top-xs text-white text-df">王者荣耀</view> <view class="margin-top-xs" style="color: #FF711B;"> <u-image width="20upx" height="20upx" style="display: inline-block;margin-right: 6upx;" src="../../static/images/index/jinbi.png"></u-image> 3币/局 </view> </view> <view @click="goOrder"> <view class="u-relative"> <u-image width="200upx" height="200upx" :src="src"></u-image> <view class="u-abso" style="bottom: 0;left: 0;color: white;background: rgba(0,0,0,.4);padding: 0 5upx;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 在线中 </view> </view> <view class="margin-top-xs text-white text-df">王者荣耀</view> <view class="margin-top-xs" style="color: #FF711B;"> <u-image width="20upx" height="20upx" style="display: inline-block;margin-right: 6upx;" src="../../static/images/index/jinbi.png"></u-image> 3币/局 </view> </view> <view @click="goOrder"> <view class="u-relative"> <u-image width="200upx" height="200upx" :src="src"></u-image> <view class="u-abso" style="bottom: 0;left: 0;color: white;background: rgba(0,0,0,.4);padding: 0 5upx;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 在线中 </view> </view> <view class="margin-top-xs text-white text-df">王者荣耀</view> <view class="margin-top-xs" style="color: #FF711B;"> <u-image width="20upx" height="20upx" style="display: inline-block;margin-right: 6upx;" src="../../static/images/index/jinbi.png"></u-image> 3币/局 </view> </view> </view> </view> <u-dropdown> <u-dropdown-item v-model="value1" title="智能优选" :options="options1"></u-dropdown-item> <u-dropdown-item v-model="value2" title="不限男女" :options="options2"></u-dropdown-item> <u-dropdown-item v-model="value3" title="价格" :options="options3"></u-dropdown-item> </u-dropdown> <!-- <view class="margin-lr-sm"> <view class="flex justify-between margin-bottom bg padding-sm" @click="goOrder"> <u-image src="../../static/images/index/image_dijia1.png" width="200upx" height="200upx" mode=""> </u-image> <view class="flex-sub margin-left text-white flex flex-direction justify-between"> <view class="flex justify-between"> <view> <view class="margin-right-xs" style="display: inline-block;"> 茗茗酱依恋 </view> <view class="round" style="display: inline-block;background-color: #582D4D; color: #FF659A;padding: 2upx 8upx;"> <u-icon name="woman" color="#FF659A" size="24"></u-icon> 24 </view> </view> <view class="radius" style="color: white;background: #243E6A;padding: 0 8upx;display: inline-block;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 西安 </view> </view> <view class="flex radius" style="background: url(../../static/images/index/bg.png)100% no-repeat;line-height: 34upx;"> <u-image src="../../static/images/index/wangzhe.png" width="34upx" height="32upx"></u-image> <text class="margin-left-xs margin-right-sm">王者荣耀</text> <text>至尊星耀</text> </view> <view class="flex" style="color: #3390FF;"> <view class="margin-right">评分5.0</view> <view>服务48人</view> </view> <view><text style="color: #FF6F1B;">7币 </text> /局</view> </view> </view> <view class="flex justify-between margin-bottom bg padding-sm" @click="goOrder"> <u-image src="../../static/images/index/image_dijia1.png" width="200upx" height="200upx" mode=""> </u-image> <view class="flex-sub margin-left text-white flex flex-direction justify-between"> <view class="flex justify-between"> <view> <view class="margin-right-xs" style="display: inline-block;"> 茗茗酱依恋 </view> <view class="round" style="display: inline-block;background-color: #582D4D; color: #FF659A;padding: 2upx 8upx;"> <u-icon name="woman" color="#FF659A" size="24"></u-icon> 24 </view> </view> <view class="radius" style="color: white;background: #243E6A;padding: 0 8upx;display: inline-block;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 西安 </view> </view> <view class="flex radius" style="background: url(../../static/images/index/bg.png)100% no-repeat;line-height: 34upx;"> <u-image src="../../static/images/index/wangzhe.png" width="34upx" height="32upx"></u-image> <text class="margin-left-xs margin-right-sm">王者荣耀</text> <text>至尊星耀</text> </view> <view class="flex" style="color: #3390FF;"> <view class="margin-right">评分5.0</view> <view>服务48人</view> </view> <view><text style="color: #FF6F1B;">7币 </text> /局</view> </view> </view> <view class="flex justify-between margin-bottom bg padding-sm" @click="goOrder"> <u-image src="../../static/images/index/image_dijia1.png" width="200upx" height="200upx" mode=""> </u-image> <view class="flex-sub margin-left text-white flex flex-direction justify-between"> <view class="flex justify-between"> <view> <view class="margin-right-xs" style="display: inline-block;"> 茗茗酱依恋 </view> <view class="round" style="display: inline-block;background-color: #582D4D; color: #FF659A;padding: 2upx 8upx;"> <u-icon name="woman" color="#FF659A" size="24"></u-icon> 24 </view> </view> <view class="radius" style="color: white;background: #243E6A;padding: 0 8upx;display: inline-block;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 西安 </view> </view> <view class="flex radius" style="background: url(../../static/images/index/bg.png)100% no-repeat;line-height: 34upx;"> <u-image src="../../static/images/index/wangzhe.png" width="34upx" height="32upx"></u-image> <text class="margin-left-xs margin-right-sm">王者荣耀</text> <text>至尊星耀</text> </view> <view class="flex" style="color: #3390FF;"> <view class="margin-right">评分5.0</view> <view>服务48人</view> </view> <view><text style="color: #FF6F1B;">7币 </text> /局</view> </view> </view> </view> --> <view style="height: 650rpx;"></view> </view> </view> </template> <script> export default { data() { return { keyword: '', TabCur: 0, tabData: [{ title: '推荐' }, { title: '王者荣耀' }, { title: '和平精英' }, { title: '英雄联盟' }, { title: '穿越火线' } ], scrollLeft: 0, swiperList: [{ image: 'https://cdn.uviewui.com/uview/swiper/1.jpg', title: '昨夜星辰昨夜风,画楼西畔桂堂东' }, { image: 'https://cdn.uviewui.com/uview/swiper/2.jpg', title: '身无彩凤双飞翼,心有灵犀一点通' }, { image: 'https://cdn.uviewui.com/uview/swiper/3.jpg', title: '谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳' } ], gridData: [{ image: '../../static/images/index/wangzhe.png', title: '王者荣耀' }, { image: '../../static/images/index/chiji.png', title: '和平精英' }, { image: '../../static/images/index/doudizhu.png', title: '斗地主' }, { image: '../../static/images/index/cf.png', title: '穿越火线' }, { image: '../../static/images/index/feiche.png', title: 'QQ飞车' }, { image: '../../static/images/index/diwurenge.png', title: '第五人格' }, { image: '../../static/images/index/yunding.png', title: '云顶之弈' }, { image: '../../static/images/index/huangye.png', title: '荒野乱斗' }, { image: '../../static/images/index/shouwang.png', title: '守望先锋' } ], src: '../../static/images/index/image_dijia1.png', value1: 1, value2: 1, value3: 1, options1: [{ label: '智能排序', value: 1, }, { label: '距离优先', value: 2, }, { label: '人气优先', value: 3, }, { label: '同城', value: 4, } ], options2: [{ label: '不限性别', value: 1, }, { label: '限男生', value: 2, }, { label: '限女生', value: 3, } ], options3: [{ label: '价格', value: 1, }, { label: '从高到低', value: 2, }, { label: '从低到高', value: 3, } ] } }, onLoad() { }, methods: { tabSelect(e) { this.TabCur = e.currentTarget.dataset.id; this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60 }, //获取地址和经纬度 getPlace() { uni.chooseLocation({ success: (res) => { console.log(res) // this.address = res.address + res.name this.address = res.name this.latitude = res.latitude this.longitude = res.longitude } }) }, // 跳转游戏列表 goNav(e) { uni.navigateTo({ url: '/pages/index/game/gameList?name=' + e.title }) }, // 跳转搜索 goSearch() { uni.navigateTo({ url: '/pages/index/search/index' }); }, // 跳转订单 goOrder() { uni.navigateTo({ url: '/pages/index/game/order' }); }, } } </script> <style> page { background-color: #111224; } .bg { background-color: #1E1F31; }原代码改为静态数据展示,简化代码并将风格改为浅色风格后的代码: </style>
11-18
<template> <view class="content"> <!-- <u-tag text="测试" type="primary" /> --> <view class="padding-lr padding-top-sm bg flex" @click.stop="goSearch"> <view class="flex justify-between margin-right-sm" @tap.stop="getPlace" style="line-height: 68rpx;"> <!-- <u-image src="/static/images/index/place.png" width="27rpx" height="37rpx" class="margin-top-xs"></u-image> --> <view class="localName text-white margin-left-sm">西安市</view> </view> <u-search placeholder="搜大神" v-model="keyword" shape="square" disabled :show-action="false" :animation="true" bg-color="#343546"></u-search> </view> <scroll-view scroll-x class="bg nav text-white"> <view class="flex text-center"> <view class="cu-item flex-sub" :class="index == TabCur ? 'text-orange cur' : ''" v-for="(item, index) in tabData" :key="index" :data-id="index" @click="tabSelect(index)"> {{ item.title }} </view> </view> </scroll-view> <view> <view class="wrap padding-sm"> <u-swiper :list="swiperList" height="360rpx" :autoplay="true" :interval="3000" :duration="500"></u-swiper> </view> <view class="" style="color: #BFBFCB;"> <u-grid :col="5" :border="false"> <u-grid-item bg-color="#111224" v-for="(item, index) in gridData" @tap="goNav(item)" :key="index"> <u-image :src="item.image" mode="" width="46" height="46"></u-image> <view class="grid-text margin-top-sm">{{ item.title }}</view> </u-grid-item> </u-grid> </view> <view class="bg margin-lr-sm padding-sm radius"> <view class="flex justify-between text-white padding-bottom-sm"> <view>乐享低价</view> <view>更多<u-image class="margin-left-sm" style="display: inline-block;" width="7upx" height="12upx" src="/static/images/index/right.png"></u-image> </view> </view> <view class="flex justify-between"> <view @click="goOrder"> <view class="u-relative"> <u-image width="100rpx" height="100rpx" :src="src"></u-image> <view class="u-abso" style="bottom: 0;left: 0;color: white;background: rgba(0,0,0,.4);padding: 0 5upx;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 在线 </view> </view> <view class="margin-top-xs text-white text-df">王者荣耀</view> <view class="margin-top-xs" style="color: #FF711B;"> <u-image width="20upx" height="20upx" style="display: inline-block;margin-right: 6upx;" src="/static/images/index/jinbi.png"></u-image> 3币/局 </view> </view> </view> </view> <u-dropdown> <u-dropdown-item v-model="value1" title="智能优选" :options="options1"></u-dropdown-item> <u-dropdown-item v-model="value2" title="不限男女" :options="options2"></u-dropdown-item> <u-dropdown-item v-model="value3" title="价格" :options="options3"></u-dropdown-item> </u-dropdown> <view class="margin-lr-sm"> <view class="flex justify-between margin-bottom bg padding-sm" @click="goOrder"> <u-image src="/static/images/index/image_dijia1.png" width="100rpx" height="100rpx" mode=""></u-image> <view class="flex-sub margin-left text-white flex flex-direction justify-between"> <view class="flex justify-between"> <view> <view class="margin-right-xs" style="display: inline-block;">茗茗酱依恋</view> <view class="round" style="display: inline-block;background-color: #582D4D; color: #FF659A;padding: 2upx 8upx;"> <u-icon name="woman" color="#FF659A" size="12"></u-icon> </view> </view> <view class="radius" style="color: white;background: #243E6A;padding: 0 8upx;display: inline-block;"> <view style="width: 10upx;height: 10upx;background: #1AD566;border-radius: 10upx;display: inline-block;margin: 0 8upx 4upx 0;"> </view> 西安 </view> </view> <view class="flex radius" style="background: url(/static/images/index/bg.png)100% no-repeat;line-height: 34upx;"> <u-image src="/static/images/index/wangzhe.png" width="34upx" height="32upx"></u-image> <text class="margin-left-xs margin-right-sm">王者荣耀</text> <text>至尊星耀</text> </view> <view class="flex" style="color: #3390FF;"> <view class="margin-right">评分5.0</view> <view>服务48人</view> </view> <view><text style="color: #FF6F1B;">7币 </text> /局</view> </view> </view> </view> <view style="height: 650rpx;"></view> </view> </view> </template> <script setup> import { ref } from 'vue'; import { onLoad, onReachBottom, onPageScroll } from '@dcloudio/uni-app' const keyword = ref(''); const TabCur = ref(0); const scrollLeft = ref(0); const swiperList = ref([ { image: 'https://dummyimage.com/600x400/000/fff', title: '昨夜星辰昨夜风,画楼西畔桂堂东' }, { image: 'https://dummyimage.com/600x400/000/fff', title: '身无彩凤双飞翼,心有灵犀一点通' }, { image: 'https://dummyimage.com/600x400/000/fff', title: '谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳' } ]); const tabData = ref([ { title: '推荐' }, { title: '王者荣耀' }, { title: '和平精英' }, { title: '英雄联盟' }, { title: '穿越火线' } ]); const gridData = ref([ { image: '/static/images/index/chiji.png', title: '王者荣耀' }, { image: '/static/images/index/chiji.png', title: '和平精英' }, { image: '/static/images/index/doudizhu.png', title: '斗地主' }, { image: '/static/images/index/cf.png', title: '穿越火线' }, { image: '/static/images/index/feiche.png', title: 'QQ飞车' }, { image: '/static/images/index/diwurenge.png', title: '第五人格' }, { image: '/static/images/index/yunding.png', title: '云顶之弈' }, { image: '/static/images/index/huangye.png', title: '荒野乱斗' }, { image: '/static/images/index/shouwang.png', title: '守望先锋' } ]); const src = ref('/static/images/index/image_dijia1.png'); const value1 = ref(1); const value2 = ref(1); const value3 = ref(1); const options1 = ref([ { label: '智能排序', value: 1 }, { label: '距离优先', value: 2 }, { label: '人气优先', value: 3 }, { label: '同城', value: 4 } ]); const options2 = ref([ { label: '不限性别', value: 1 }, { label: '限男生', value: 2 }, { label: '限女生', value: 3 } ]); const options3 = ref([ { label: '价格', value: 1 }, { label: '从高到低', value: 2 }, { label: '从低到高', value: 3 } ]); // 生命周期 onLoad(() => { // 如果 swiperList 是异步加载的,这里赋值后强制刷新 // 示例:api.getSwiper().then(res => { // swiperList.value = res.data; // nextTick(() => {}); // 确保视图更新 // }); }); // 方法 const tabSelect = (index) => { TabCur.value = index; scrollLeft.value = (index - 1) * 60; }; const getPlace = () => { uni.chooseLocation({ success: (res) => { console.log(res); // this.address = res.address + res.name; // Vue 3 中直接用 ref // address.value = res.name; // 如果有 address ref // latitude.value = res.latitude; // longitude.value = res.longitude; } }); }; const goNav = (item) => { uni.navigateTo({ url: '/pages/index/game/gameList?name=' + item.title }); }; const goSearch = () => { uni.navigateTo({ url: '/pages/index/search/index' }); }; const goOrder = () => { uni.navigateTo({ url: '/pages/index/game/order' }); }; </script> <style> page { background-color: #111224; } .bg { background-color: #1E1F31; } </style>简化样式,写出代码
11-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值