标签:codeforces gcd 思维题
题意:在n*n的上从左下角开始,每次走n+1个点画一个叉,问回到起点时一共画几个叉;
思路:gcd;
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; long long n,m,num,t,a,b,r; int i,j,k,rcount,shu,flag,yu,len; long long gcd(long long a,long long b) { long long c; c=a%b; while(c) { a=b; b=c; c=a%b; } return b; } int main() { while(cin>>t) { while(t--) { cin>>n; a=4*n,b=n+1; num=4*n/gcd(a,b)+1; cout<<num<<endl; } } return 0; }
标签:codeforces gcd 思维题
原文地址:http://blog.csdn.net/dominating413421391/article/details/43537323