当前位置:网站首页>踩水坑2 数据超出long long
踩水坑2 数据超出long long
2022-07-31 09:30:00 【繁水682】
不能想当然认为数据一定小于long long
一定要仔细判断数据范围!
一定要仔细判断数据范围!
一定要仔细判断数据范围!
如果不行了,就可以用赖皮方法,__int128(两个下划线)
__int128只能用于数据中间处理,不能用作输入输出。
用法:
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define pii pair<int,int>
#define pb push_back
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define nep(i,r,l) for (int i=r;i>=l;i--)
#define CIO std::ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
const int N=2e6+5;
int aa[N];
int bb[N];
map<int,int> m;
void lg(int x){
int cnt=0;
while (x){
if (x&1) m[cnt+1]++;
x=x/2;
cnt++;
}
}
int ansz,ansm;
__int128 gcd(__int128 a,__int128 b){
if (b==0) return a;
return gcd(b,a%b);
}
int pre[40];
void work(){
int n;cin>>n;
int sum=0;
rep(i,1,n){
cin>>aa[i];
sum+=aa[i];
lg(aa[i]);
}
int SUM=sum;
pre[1]=1;
rep(i,2,30){
pre[i]=pre[i-1]*2;
}
rep(i,1,30){
rep(j,1,m[i]){
bb[j]+=pre[i];
}
}
__int128 ans=0;
__int128 zhuan=0;
rep(i,1,n){
zhuan=(bb[i]*n-SUM);
zhuan*=(bb[i]*n-SUM);
ans+=zhuan;
}
__int128 nn=n*n*n;
__int128 g=gcd(ans,nn);
int ans1=ans/g;
int ans2=(n*n*n)/g;
if (ans==0) cout<<"0/1";
else cout<<ans1<<"/"<<ans2;
}
signed main(){
CIO;
//int _;cin>>_;while(_--)
{
work();
}
return 0;
}
边栏推荐
- JSP exception对象简介说明
- Linux安装mysql
- @RequestBody和@RequestParam区别
- 7. JS ES6新增语法 new Map详讲,还有一道代码实战案例帮你快上手new Map
- 如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南
- Modular specifications
- Pytorch学习记录(七):自定义模型 & Auto-Encoders
- Canvas particles change various shapes js special effects
- Progressive Web App(PWA)
- js滚动条滚动到指定元素
猜你喜欢
随机推荐
Flink1.15 source code reading flink-clients - flink command line help command
Flink1.15源码阅读——PER_JOB vs APPLICATION执行流程
生成随机数
jupyter notebook初使用
Flink1.15源码阅读flink-clients——flink命令行帮助命令
VMware下安装win10
【RISC-V】risc-v架构学习笔记(架构初学)
通过栗子来学习MySQL高级知识点(学习,复习,面试都可)
刷题《剑指Offer》day07
js implements the 2020 New Year's Day countdown bulletin board
OpenGL es 初识
A brief introduction to the SSM framework
djangoWeb应用框架+MySQL数据4
二叉树的搜索与回溯问题(leetcode)
一些计时软件,生产力工具
MySQL 高级(进阶) SQL 语句 (一)
02 Truffle TutorialToken 示例
The future of the hybrid interface: conversational UI
感情危机,朋友的网恋女友要和他闹分手,问我怎么办
基于学生成绩管理系统(附源代码及数据库)