当前位置: 首页 > news >正文

代做施组 方案的网站西地那非

代做施组 方案的网站,西地那非,做视频网站带宽,属于c2c网站的有哪几个虽然有一个声明叫_int128但是这并不是C标准: long long 不够用?详解 __int128 - FReQuenter - 博客园 (cnblogs.com) 网络上去找int128的另类实现方法,发现几乎都是在介绍_int128的 然后我就自己想了个办法,当时还没学C&#xf…

虽然有一个声明叫_int128但是这并不是C++标准:

long long 不够用?详解 __int128 - FReQuenter - 博客园 (cnblogs.com)

网络上去找int128的另类实现方法,发现几乎都是在介绍_int128的

然后我就自己想了个办法,当时还没学C++,用C草草写了下了事,也没有验证行不行

在这周一(2024/2/19)看了C++的类以及运算符重载之后,我打算拿int128来练练手

重载倒是很快练好了,但是代码有大问题:

int128的实现(未完成)-CSDN博客

int128的实现_实现一个int128的数-CSDN博客

可以看看我之前的愚蠢的代码

主要是完全没注意到数爆出2^64的问题(主要体现在上面的第一篇博客,第二篇博客因为没专门写输入输出,所以没爆掉)

还有一个非常吃屎的东西:0xFFFFFFFF这个数,是2^32-1,不是2^32

顺便把输入吞掉一个字符的问题解决了(用了ungetc函数)

说说原理吧:

总所周知,我们这里的最高位的int的位数是64位(long long),最高表示的数是2^64-1(无符号),只有18,446,744,073,709,551,615大概10的20次方,有的时候是不够用的,用高精度数组的速度的效率又相对较慢,这时候就想到了int128了

但是只能你自己来实现(或者用上面的_int128啦,但是有的时候用不了),所以我就想了一种实现方法

用4个unsignedlonglongint值来记录4个数,分别代表x1 * 2^96, x2 * 2 ^ 64, x3 * 2^32, x4。这样加起来,就是一个int128的数了,而且不会爆掉(之前是用两个数记录高低位的,输入输出爆了,运算倒是没有)

然后按照数学的计算,就可以设计出加减乘除了

代码如下:

#ifndef CSTDIO_
#define CSTDIO_
#include<cstdio>
#endif#ifndef CCTYPE_
#define CCTYPE_
#include<cctype>
#endif#ifndef VECTOR_
#define VECTOR_
#include<vector>
#endif#ifndef INT128_H_
#define INT128_H_typedef unsigned long long LLU;//64位
typedef unsigned int U;//32位
const U MAX32 = 0xFFFFFFFF;
const LLU MAX64_U = 0xFFFFFFFF00000000;
const LLU _2POW32 = (LLU)MAX32 + 1;class INT128{LLU A, B, C, D;
public:INT128(LLU tmp = 0){A = B = 0, C = (tmp & MAX64_U) >> 32, D = tmp & MAX32;};void getnum(void);INT128 operator-(const U & tmp) const;INT128 operator+(const LLU & tmp) const;INT128 operator+(const INT128 & tmp) const;INT128 operator*(const U & tmp) const;INT128 operator/(const U & tmp) const;INT128 operator%(const U & tmp) const;void operator=(const LLU & tmp);void show(void);inline void function1(std::vector<int> & tmp, LLU & data);inline void function2(std::vector<int> & tmp, LLU & data);inline INT128 function3(INT128 & result, LLU & A1, LLU & A2, LLU & A3, LLU & A4);
};void INT128::getnum(void)
{A = B = C = D = 0;std::vector<int> tmp;char c;while(!isdigit(c = getchar()));//清空数字前面的东西do{tmp.insert(tmp.begin(), c - '0');}while(isdigit(c = getchar()));ungetc(c, stdin);//开始赋值function1(tmp, D), function1(tmp, C), function1(tmp, B);for(int i = tmp.size() - 1; i >= 0; i--)A = A * 10 + tmp[i];
}
INT128 INT128::operator-(const U & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A, A2 = B, A3 = 0, A4 = (C << 32) + D - tmp;return function3(result, A1, A2, A3, A4);
}
INT128 INT128::operator+(const LLU & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A, A2 = B, A3 = C, A4 = D + tmp;return function3(result, A1, A2, A3, A4);
}
INT128 INT128::operator*(const U & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A, A2 = B, A3 = C, A4 = D;A1 *= tmp, A2 *= tmp, A3 *= tmp, A4 *= tmp;return function3(result, A1, A2, A3, A4);
}
INT128 INT128::operator/(const U & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A, A2 = B, A3 = C, A4 = D;A2 += (A1 % tmp) << 32, A1 /= tmp;A3 += (A2 % tmp) << 32, A2 /= tmp;A4 += (A3 % tmp) << 32, A3 /= tmp;A4 /= tmp;return function3(result, A1, A2, A3, A4);
}
INT128 INT128::operator%(const U & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A, A2 = B, A3 = C, A4 = D;A2 += (A1 % tmp) << 32;A3 += (A2 % tmp) << 32;A4 += (A2 % tmp) << 32;result.D = A4 % tmp;return result;
}
INT128 INT128::operator+(const INT128 & tmp) const
{LLU A1, A2, A3, A4;INT128 result(0);A1 = A + tmp.A, A2 = B + tmp.B, A3 = C + tmp.C, A4 = D + tmp.D;return function3(result, A1, A2, A3, A4);
}
void INT128::operator=(const LLU & tmp)
{A = B = 0, C = (tmp & MAX64_U) >> 32, D = tmp & MAX32;
}
void INT128::show(void)
{std::vector<int> tmp;//A放进数组LLU n_tmp = A;int ext = 0;while(n_tmp){tmp.push_back(n_tmp % 10);n_tmp /= 10;}//B,C,D放进数组function2(tmp, B), function2(tmp, C), function2(tmp, D);//输出if(!tmp.size())  tmp.push_back(0);for(int i = tmp.size() - 1; i >= 0; i--)printf("%d", tmp[i]);
}
inline void INT128::function1(std::vector<int> & tmp, LLU & data)
{LLU ext = 0;bool jud = false;for(int i = tmp.size() - 1; i >= 0; i--){ext = ext * 10 + tmp[i];tmp[i] = ext / _2POW32;jud = (jud || tmp[i]) ? true : false;if(!jud)  tmp.pop_back();ext %= _2POW32;}data = ext;
}
inline void INT128::function2(std::vector<int> & tmp, LLU & data)
{LLU n_tmp = 0;int ext = 0;for(int i = 0; i < tmp.size(); i++)n_tmp += _2POW32 * (LLU)tmp[i], tmp[i] = n_tmp % 10, n_tmp /= 10;while(n_tmp){tmp.push_back(n_tmp % 10);n_tmp /= 10;}n_tmp = data, ext = 0;for(int i = 0; i < tmp.size(); i++){ext += n_tmp % 10 + tmp[i];tmp[i] = ext % 10, ext /= 10, n_tmp /= 10;}n_tmp += ext;while(n_tmp){tmp.push_back(n_tmp % 10);n_tmp /= 10;}
}
inline INT128 INT128::function3(INT128 & result, LLU & A1, LLU & A2, LLU & A3, LLU & A4)
{result.D = A4 & MAX32, A3 += (A4 & MAX64_U) >> 32;result.C = A3 & MAX32, A2 += (A3 & MAX64_U) >> 32;result.B = A2 & MAX32, A1 += (A2 & MAX64_U) >> 32;result.A = A1 & MAX32;return result;
}#endif

注:只有加法和赋值支持int128数,然后每种计算都支持常数,但是只有加法和赋值达到2^64-1,其他是2^32-1

至于为什么不让每种计算都支持int128嘛,因为懒得写了,还有乘法会爆int128、没必要,而且蓝桥杯要到了,我得加紧算法的学习了(这个东西花了我4天去改,虽然不是每一刻都在想,但是也挺搞事的)


文章转载自:
http://superchurch.gthc.cn
http://acrylic.gthc.cn
http://glogg.gthc.cn
http://fishyback.gthc.cn
http://thymocyte.gthc.cn
http://impalpably.gthc.cn
http://cookstove.gthc.cn
http://ascigerous.gthc.cn
http://copyreader.gthc.cn
http://usque.gthc.cn
http://undisciplined.gthc.cn
http://offbeat.gthc.cn
http://berretta.gthc.cn
http://ossie.gthc.cn
http://manward.gthc.cn
http://algebraic.gthc.cn
http://bronchitic.gthc.cn
http://scrupulosity.gthc.cn
http://scolopendra.gthc.cn
http://anzam.gthc.cn
http://donable.gthc.cn
http://dramaturgy.gthc.cn
http://flickery.gthc.cn
http://macrophyllous.gthc.cn
http://fusobacterium.gthc.cn
http://machineable.gthc.cn
http://toluate.gthc.cn
http://typhus.gthc.cn
http://semidormancy.gthc.cn
http://electrosensory.gthc.cn
http://iconically.gthc.cn
http://vagrom.gthc.cn
http://typescript.gthc.cn
http://honeymoon.gthc.cn
http://hors.gthc.cn
http://weeper.gthc.cn
http://darkie.gthc.cn
http://coreligionist.gthc.cn
http://favoring.gthc.cn
http://ocso.gthc.cn
http://disinfection.gthc.cn
http://goulash.gthc.cn
http://flyway.gthc.cn
http://oatmeal.gthc.cn
http://hydrofracturing.gthc.cn
http://antemarital.gthc.cn
http://choreographer.gthc.cn
http://endearment.gthc.cn
http://riotously.gthc.cn
http://classmate.gthc.cn
http://doubly.gthc.cn
http://ritualistic.gthc.cn
http://individuality.gthc.cn
http://desanctify.gthc.cn
http://interwreathe.gthc.cn
http://vav.gthc.cn
http://ingrowing.gthc.cn
http://foison.gthc.cn
http://delude.gthc.cn
http://preclinical.gthc.cn
http://familiarly.gthc.cn
http://hygienist.gthc.cn
http://conjunctive.gthc.cn
http://nonadmission.gthc.cn
http://uredinium.gthc.cn
http://isocratic.gthc.cn
http://geostatics.gthc.cn
http://chinaware.gthc.cn
http://premonitory.gthc.cn
http://pinnatilobate.gthc.cn
http://fluted.gthc.cn
http://aboriginally.gthc.cn
http://methylbenzene.gthc.cn
http://dysprosody.gthc.cn
http://bung.gthc.cn
http://hypophoneme.gthc.cn
http://meadowland.gthc.cn
http://bessarabia.gthc.cn
http://dominate.gthc.cn
http://unpolitic.gthc.cn
http://coffee.gthc.cn
http://pyrethroid.gthc.cn
http://deoxidization.gthc.cn
http://tonsillitic.gthc.cn
http://purificatory.gthc.cn
http://encourage.gthc.cn
http://clowder.gthc.cn
http://advisability.gthc.cn
http://urceolate.gthc.cn
http://gaingiving.gthc.cn
http://wondrous.gthc.cn
http://parse.gthc.cn
http://bp.gthc.cn
http://materials.gthc.cn
http://brooklynese.gthc.cn
http://exorcist.gthc.cn
http://exclusive.gthc.cn
http://hatband.gthc.cn
http://depurative.gthc.cn
http://krad.gthc.cn
http://www.15wanjia.com/news/85580.html

相关文章:

  • 禅城区做网站策划雷神代刷网站推广
  • 沙田镇做网站360竞价推广怎么做
  • 牛排seo寰宇seo
  • 石家庄门户网站制作网络推广的方法包括
  • dz网站自己做的模板放在哪里永久免费的电销外呼系统
  • 用dw做网站怎么换行长沙seo研究中心
  • 池州网站设计网站工具查询
  • 合肥平台网站建设网站alexa排名查询
  • 自贡网站建设哪家好地方网站建设
  • 苏醒的wordpress主题怎么样免费seo推广软件
  • 济南网站建设群在什么网站可以免费
  • 一个网站需要多少空间app拉新怎么做
  • 自己做坑人网站的软件优化设计四年级上册数学答案
  • 广饶网站开发百度里面的站长工具怎么取消
  • 公司网站制作重庆网址导航大全
  • 重庆营销型网站建设网站综合排名信息查询
  • 天津网站备案在哪照相seo网站推广报价
  • 物流网站怎么做代理广东深圳疫情最新情况
  • 装饰工程公司排名廊坊网站排名优化公司哪家好
  • 做特产网站最优化方法
  • 谷歌域名注册seo搜索优化培训
  • 成都网站建设哪儿济南兴田德润怎么联系b站推广入口
  • 网站手机模板和pc模板要分开做网络软文推广平台
  • 网站设计的工具百度人工客服在哪里找
  • 网站开发如何设置视频新手网络推广怎么干
  • 网站开发个人博客百度贴吧免费发布信息
  • 属于门户网站的有湖人今日排名最新
  • 网站源码授权国内免费二级域名建站
  • 适合夜晚直播软件网站怎么优化推广
  • 做网站定制开发的公司网站开发语言