#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#define cl(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const db pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862;
void gn(int &x){
int sg=;char c;while(((c=getchar())<''||c>'')&&c!='-');
if(c=='-')sg=-,x=;else x=c-'';
while((c=getchar())>=''&&c<='')x=x*+c-'';
x*=sg;
}
void gn(ll &x){
int sg=;char c;while(((c=getchar())<''||c>'')&&c!='-');
if(c=='-')sg=-,x=;else x=c-'';
while((c=getchar())>=''&&c<='')x=x*+c-'';
x*=sg;
}
int mo=;
int inf=;
db eps=1e-;
//ll inf=1000000000000000000ll;
int qp(int a,ll b){int ans=;do{if(b&)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[]={,,-,};
int dy[]={,,,-};
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789 #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std; // upd 2015.11.28
class Bignum{
private:
vector<int>a;
void clear(){a.resize();a[]=;}
void set(int n){
if(clear(),n){
int t;a.clear();
while(n)a.push_back(n-(t=n/)*),n=t;
}
}
void set(long long n){
if(clear(),n){
long long t;a.clear();
while(n)a.push_back(n-(t=n/)*),n=t;
}
}
void clearzero(){
int l=a.size();
while(l> && a[l-]==)l--;
a.resize(l);
}
void set(char*st){
char c;vector<int> s;a.clear();
while(((c=*(st++))<'' || c>''));s.push_back(c-'');
while((c=*(st++))>=''&&c<='')s.push_back(c-'');
int l=s.size();
for (int i=l-;i->=;i-=)a.push_back(s[i]+s[i-]*+s[i-]*+s[i-]*);
if(l&){
int tmp=;
for (int i=;i<(l&);i++)tmp=tmp*+s[i];
a.push_back(tmp);
}
clearzero();
}
public:
Bignum(){clear();}
Bignum(int n){set(n);}
Bignum(long long n){set(n);}
Bignum(char*s){set(s);}
Bignum& operator=(int a){set(a);return *this;}
Bignum& operator=(long long a){set(a);return *this;}
Bignum& operator=(char *s){set(s);return *this;}
int size()const{
if(a.back()>=)return a.size()<<;
else if(a.back()>=)return (a.size()<<)-;
else if(a.back()>=)return (a.size()<<)-;
else return (a.size()<<)-;
}
long long toint()const{
long long ans=;
for (int i=int(a.size())-;i>=;i--)ans=ans*+a[i];
return ans;
}
int tostr(char *s)const{
int tot=;
for (unsigned int i=;i<a.size();i++)
if(i+==a.size()){
int x=a[i];
while(x)s[tot++]=''+x%,x/=;
}else{
int x=a[i];
for (int j=;j<;j++)s[tot++]=''+x%,x/=;
}
if(tot==)s[tot++]='';
for (int i=,j=tot-;i<j;i++,j--)swap(s[i],s[j]);
s[tot]=;
return tot;
}
int toarr(int *s)const{
int tot=;
for (unsigned int i=;i<a.size();i++)
if(i+==a.size()){
int x=a[i];
while(x)s[tot++]=x%,x/=;
}else{
int x=a[i];
for (int j=;j<;j++)s[tot++]=x%,x/=;
}
if(tot==)s[tot++]=;
return tot;
}
int comp(const Bignum&x)const{
if(a.size()<x.a.size())return ;
if(a.size()>x.a.size())return -;
for (int i=a.size()-;i>=;i--)
if(a[i]<x.a[i])return ;
else if(a[i]>x.a[i])return -;
return ;
}
bool operator<(const Bignum&x)const{return comp(x)==;}
bool operator>(const Bignum&x)const{return comp(x)==-;}
bool operator<=(const Bignum&x)const{return comp(x)!=-;}
bool operator>=(const Bignum&x)const{return comp(x)!=;}
bool operator!=(const Bignum&x)const{return comp(x)!=;}
bool operator==(const Bignum&x)const{return comp(x)==;}
Bignum& operator+=(const Bignum&x){
int l=max(a.size(),x.a.size())+;
a.resize(l);
for (unsigned int i=;i<x.a.size();i++)a[i]+=x.a[i];
for (int i=;i<l;i++)if(a[i]>=)a[i]-=,a[i+]++;
clearzero();return *this;
}
Bignum& operator-=(const Bignum&x){
for (unsigned int i=;i<x.a.size();i++)a[i]-=x.a[i];
for (unsigned int i=;i<a.size();i++)if(a[i]<)a[i]+=,a[i+]--;
clearzero();return *this;
}
Bignum operator+(const Bignum&x)const{Bignum y=*this;y+=x;return y;}
Bignum operator-(const Bignum&x)const{Bignum y=*this;y-=x;return y;}
Bignum operator*(const Bignum&x)const{
int l=a.size()+x.a.size();
Bignum z;z.a.clear();
vector<long long>tmp;tmp.resize(l);
for (unsigned int i=;i<x.a.size();i++)
for (unsigned int j=;j<a.size();j++)
tmp[i+j]+=x.a[i]*a[j];
for (int i=;i<l;i++){
long long t=tmp[i]/;
z.a.push_back(int(tmp[i]-t*));
t?tmp[i+]+=t:;
}
z.clearzero();return z;
}
Bignum operator*(long long x)const{
if(x>=)return *this * Bignum(x);
int l=a.size()+;
Bignum z;z.a.resize(l);
for (unsigned int i=;i<a.size();i++)z.a[i]=a[i]*x;
for (int i=,t;i<l;i++)z.a[i+]+=(t=z.a[i]/),z.a[i]-=t*;
z.clearzero();return z;
}
friend Bignum operator*(long long x,const Bignum&a){return a*x;}
Bignum& operator*=(long long x){return *this=*this*x;}
Bignum& operator*=(const Bignum&x){return *this=*this*x;}
Bignum operator/(const Bignum &x)const{
Bignum b=*this,q,tmp;q.a.resize(b.a.size());
for(int i=int(b.a.size())-int(x.a.size());b>=x;i--,b.clearzero()){
tmp.a.assign(b.a.begin()+i,b.a.end());
int l=,r=-,m;
while(l<=r){
m=(l+r)>>;
if(x*m<=tmp)l=m+;
else r=m-;
}
for (unsigned int j=;j<tmp.a.size();j++)b.a[j+i]=;
q.a[i]=r;tmp-=x*r;
for (unsigned int j=;j<tmp.a.size();j++)b.a[j+i]=tmp.a[j];
}
q.clearzero();return q;
}
Bignum operator%(const Bignum &x)const{return *this-*this/x*x;}
Bignum& operator/=(const Bignum &x){return *this=*this/x;}
Bignum& operator%=(const Bignum &x){return *this=*this%x;} Bignum& operator/=(long long x){
if(x>=)return *this/=Bignum(x);
else{
for (int i=int(a.size())-;i>=;i--){
int t=a[i]/x;
if(i)a[i-]+=(a[i]-t*x)*;
a[i]=t;
}
clearzero();
return *this;
}
}
Bignum operator/(long long x)const{
if(x>=)return *this / Bignum(x);
else{
Bignum y=*this;y/=x;return y;
}
}
long long operator%(long long x)const{
if(x>=)return (*this%Bignum(x)).toint();
else{
long long ans=;
for (int i=int(a.size())-;i>=;i--)ans=(ans*+a[i])%x;
return ans;
}
}
int operator%(int x)const{
return int(operator%((long long)x));
}
Bignum& operator%=(long long x){
if(x>=)return *this%=Bignum(x);
else return *this=*this%x;
}
int to2(int *s)const{
int tot=;
vector<unsigned long long>t;
for (unsigned int i=;i<a.size();i++)t.push_back((unsigned long long)a[i]);
while(!t.empty()){
for (int i=int(t.size())-;i>=;i--){
unsigned long long r=t[i]>>;
if(i==){
s[tot++]=int(t[i]&0xffffffff);
}else{
t[i-]+=(t[i]&((unsigned long long)0xffffffff))*;
}
t[i]=r;
}
while(!t.empty() && t.back()==)t.pop_back();
}
return tot;
}
bool input(){
char c;vector<int> s;a.clear();
while(((c=getchar())<'' || c>'') && c!=EOF);
if(c==EOF){a.push_back();return ;}
s.push_back(c-'');
while((c=getchar())>=''&&c<='')s.push_back(c-'');
int l=s.size();
for (int i=l-;i->=;i-=)a.push_back(s[i]+s[i-]*+s[i-]*+s[i-]*);
if(l&){
int tmp=;
for (int i=;i<(l&);i++)tmp=tmp*+s[i];
a.push_back(tmp);
}
clearzero();
return ;
}
void output()const{
for (int i=int(a.size())-;i>=;i--)
if(i==int(a.size())-)printf("%d",a[i]);
else printf("%04d",a[i]);
}
void outputln()const{
output();putchar('\n');
}
friend Bignum max(const Bignum &a,const Bignum &b){return a>b?a:b;}
friend Bignum min(const Bignum &a,const Bignum &b){return a<b?a:b;}
};
Bignum a,N;
int main()
{
int tes;gn(tes);
while(tes--){
int n;gn(n);
if(n<=){
printf("%d\n",n*(n-)*(n-)*(n-)/+n);
}else{
N=n;
a=N*(N-)*(N-)*(N-)/+N;
a.outputln();
}
}
return ;
}

高精度模板(From JCVB)的更多相关文章

  1. [Template]高精度模板

    重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...

  2. C++高精度模板

    原文地址:http://blog.csdn.net/wall_f/article/details/8373395 原文只附代码,没有解析,本文增加了一些对代码的解释. 请注意:本模板不涉及实数运算与负 ...

  3. [note]高精度模板

    高精度模板 先定义一个struct struct gj{ int l,s[N]; bool fh; void Print(){ if(fh)putchar('-'); for(int i=l;i> ...

  4. 高精度模板 支持各种运算 c++

    绪言 自从有了高精度模板,妈妈再也不用怕我不会打高精度了! 代码 代码长度与日俱增啊~~~ #include<iostream> #include<cstring> #incl ...

  5. 高精度模板 Luogu P1932 A+B & A-B & A*B & A/B Problem

    P1932 A+B & A-B & A*B & A/B Problem 题目背景 这个题目很新颖吧!!! 题目描述 求A.B的和差积商余! 输入输出格式 输入格式: 两个数两行 ...

  6. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  7. JAVA高精度模板

    刚开始还坚持用C++写高精来着,后来发现JAVA写高精方便太多了,所以也来学习一下JAVA高精度的模板. 参考:https://www.cnblogs.com/imzscilovecode/p/883 ...

  8. 高精度模板 洛谷Luogu P1932 A+B & A-B & A*B & A/B Problem

    P1932 A+B & A-B & A*B & A/B Problem 题目背景 这个题目很新颖吧!!! 题目描述 求A.B的和差积商余! 输入输出格式 输入格式: 两个数两行 ...

  9. [SinGuLaRiTy] 复习模板-高精度模板

    [SinGuLaRiTy-1042] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 结构体封装 //高精度运算 注意%I64d与%lld # ...

随机推荐

  1. IOS代码收集

    http://mobile.51cto.com/hot-410417.htm 退回输入键盘: - (BOOL) textFieldShouldReturn:(id)textField{ [textFi ...

  2. IOS应用

    下面是这个类的一些功能: 1.设置icon上的数字图标 //设置主界面icon上的数字图标,在2.0中引进, 缺省为0 [UIApplicationsharedApplication].applica ...

  3. Python 风格规范

    分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行.     行长度 每行不超过80 个字符 例外: 如果使用Python 2.4 或更早的版本, 导入模块的行可能多于80 个字符. Pyth ...

  4. Android(java)学习笔记180:多媒体之图形的变化处理

    1. 图形的缩放 (1)布局文件activity_main.xml如下: <LinearLayout xmlns:android="http://schemas.android.com ...

  5. Python3简明教程(二)—— 变量和数据类型

    关键字和标识符 下列的标识符是Python3的关键字,并且不能用于通常的标识符.关键字必须严格按照下面的拼写: False def if raise None del import return Tr ...

  6. upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量

    upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量 <Upload ...

  7. 跑RFCN

    按照这个来http://blog.csdn.net/sinat_30071459/article/details/53202977

  8. Java集合系列之HashMap

    概要 第1部分 HashMap介绍 HashMap简介 HashMap 是一个散列表,它存储的内容是键值对(key-value)映射.HashMap 继承于AbstractMap,实现了Map.Clo ...

  9. java 数据库(二)

    1.SQL概述 1.什么是SQL(了解): 结构化查询语言,是一种功能齐全的数据库语言.在使用它时,只需要发出“做什么”的命令,“怎么做”是不用使用者考虑的 SQL被美国国家标准局(ANSI)确定为关 ...

  10. JavaScript 非常重要的几个概念

    JavaScript是一门比较复杂的语言.如果你是一名JavaScript开发人员,不管处于什么样的水平,都有必要了解JavaScript的基本概念.小编最近的工作涉及到JavaScript,于是本文 ...