欧拉平面公式证明:点击打开链接
题目链接:点击打开链接
import java.math.BigInteger;
import java.util.*;
/*
第一道java题,简单在不用模拟,但是要记住这一堆规则
1. 头文件 import java.math.BigInteger; import java.util.*;//大数头文件和 一些标准头文件,
2. 函数名必须写Main(),函数前面都加上 public static
3. 输入 Scanner cin=new Scanner(System.in), 后面就都是int n=cin.nextInt(),BigInteger a=cin.nextBigInteger();
4. 多组输入,直接while(cin.hasNext()){},不管几个都是这样写
5 .输出 System.out.println()
*/
public class Main {
public static BigInteger get(BigInteger n) {
BigInteger v1=n.subtract(BigInteger.valueOf(2));
BigInteger v2=n.subtract(BigInteger.valueOf(3));
BigInteger v3=n.multiply(BigInteger.valueOf(2)).subtract(BigInteger.valueOf(5));
return v1.multiply(v1).multiply(v2).divide(BigInteger.valueOf(2)).subtract(v1.multiply(v2).multiply(v3).divide(BigInteger.valueOf(6)));
}
public static BigInteger getv(BigInteger n) {
BigInteger ans=n;
BigInteger tmp=get(n);
ans=ans.add(n.multiply(tmp).divide(BigInteger.valueOf(4)));
return ans;
}
public static BigInteger gete(BigInteger n) {
BigInteger ans=n.multiply(BigInteger.valueOf(2));
BigInteger tmp=get(n);
tmp=tmp.add(n.subtract(BigInteger.valueOf(3)));
ans=ans.add(n.multiply(tmp).divide(BigInteger.valueOf(2)));
return ans;
}
public static void main(String[] args) {
int ans[]= {1,1,2,4,8,16,31};
Scanner cin=new Scanner(System.in);
while(cin.hasNext()) {//多组输入,一直到EOF
int m=cin.nextInt();
for(int i=1;i<=m;i++) {
int n=cin.nextInt();
if(n<5) {
System.out.println(ans[n]);
continue;
}
BigInteger V=getv(BigInteger.valueOf(n));
BigInteger E=gete(BigInteger.valueOf(n));
BigInteger ed=E.add(BigInteger.valueOf(1)).subtract(V);
System.out.println(ed);
}
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct BIGNUM{
static const int maxn=1000;
static const int base=10000;
static const int dlen=4;
int d[maxn],len;
BIGNUM (){memset(d,0,sizeof(d));len=1;}
BIGNUM(int x){
memset(d,0,sizeof(d));
len=0;
do{
d[len++]=x%base;
x/=base;
}while(x);
}
BIGNUM(const char s[])
{
memset(d,0,sizeof(d));
len=strlen(s);
for(int cnt=0;dlen*cnt<=len;cnt++)
for(int j=dlen;j>=1;j--)
if(len-cnt*dlen-j>=0) d[cnt]=d[cnt]*10+s[len-cnt*dlen-j]-'0';
len=len/dlen+(len%dlen!=0);
}
bool operator==(BIGNUM b){
if(len!=b.len)return false;
for(int i=0;i<len;i++)if(d[i]!=b.d[i])return false;
return true;
}
BIGNUM operator + (const BIGNUM& b)const{
BIGNUM res;
res.len=max(len,b.len);
for(int i=0;i<res.len;i++){
res.d[i]+=(i<len?d[i]:0)+(i<b.len?b.d[i]:0);
res.d[i+1]+=res.d[i]/base;
res.d[i]%=base;
}
if(res.d[res.len]>0)res.len++;
return res;
}
BIGNUM operator += (const BIGNUM& b){return *this=*this+b;}
BIGNUM operator - (const BIGNUM& b)const{
BIGNUM c;c.len=len;
for(int i=0;i<len;i++)
{
c.d[i]=c.d[i]+d[i]-b.d[i];
if(c.d[i]<0) c.d[i]+=base,c.d[i+1]-=1;
}
while(c.d[c.len-1]==0&&c.len>1) c.len--;
return c;
}
BIGNUM operator -= (const BIGNUM& b){return *this=*this-b;}
BIGNUM operator *(const BIGNUM& x)
{
BIGNUM c;
c.len=len+x.len;
for(int i=0;i<x.len;i++)
for(int j=0;j<len;j++)
{
c.d[i+j]+=d[j]*x.d[i];
c.d[i+j+1]+=c.d[i+j]/base;
c.d[i+j]%=base;
}
while(c.d[c.len-1]==0&&c.len>1)c.len--;
return c;
}
BIGNUM operator *=(const BIGNUM& b){return *this=*this * b;}
BIGNUM operator / (const int &b)const{//高精除低精做法
BIGNUM c;c.len=len;
long long x=0;
for(int i=len-1;i>=0;--i)
{
x=x*base+d[i];
c.d[i]=x/b;
x%=b;
}
while(c.d[c.len-1]==0&&c.len>1) --c.len;
return c;
}
void output(){
printf("%d",d[len-1]);
for(int i=len-2;i>=0;i--)printf("%04d",d[i]);
}
};
char SSS[1000];
istream& operator >> (istream& in,BIGNUM &x){
in>>SSS;x=SSS;
return in;
}
ostream& operator << (ostream& out,const BIGNUM &x)
{
printf("%d",x.d[x.len-1]);
for(int i=x.len-2;i>=0;i--)printf("%04d",x.d[i]);
return out;
}
//end
typedef BIGNUM BI;
BI getv(BI n){
if(n==BI(1)) return BI(1);
if(n==BI(2)) return BI(2);
BI tmp1=(n-BI(2))*(n-BI(2))*(n-BI(3))/2;
BI tmp2=(n-BI(3))*(n-BI(2))*(BI(2)*n-BI(5))/6;
return (tmp1-tmp2)*n/4+n;
}
BI gete(BI n){
if(n==BI(1)) return BI(1);
if(n==BI(2)) return BI(3);
BI tmp1=(n-BI(2))*(n-BI(2))*(n-BI(3));
tmp1=tmp1/2;
BI tmp2=(n-BI(3))*(n-BI(2))*(BI(2)*n-BI(5))/6;
return (tmp1-tmp2+n-BI(3))*n/2+BI(2)*n;
}
int main()
{
int T;cin>>T;
while(T--){
int n;
scanf("%d",&n);
BI V=getv(n);
BI E=gete(n);
cout<<E+BI(1)-V<<endl;
}
return 0;
}