当前位置:网站首页>踩水坑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;
}
边栏推荐
猜你喜欢
js implements the 2020 New Year's Day countdown bulletin board
VMware下安装win10
来n遍剑指--05. 替换空格
【问题记录】TypeError: eval() arg 1 must be a string, bytes or code object
Define event types in Splunk Web
js实现2020年元旦倒计时公告牌
Are postgresql range queries faster than index queries?
二叉树的搜索与回溯问题(leetcode)
第二十二课,实例化(instancing)
Redis Sentinel原理
随机推荐
【Redis高手修炼之路】Jedis——Jedis的基本使用
傅里叶变换,拉普拉斯变换学习记录
js radar chart statistical chart plugin
(C语言)程序环境和预处理
postgresql 生成随机日期,随机时间
各位大佬,sqlserver 支持表名正则匹配吗
Modular specifications
多个js雷达图同时显示
优信年营收16亿:亏损3亿 已与蔚来资本及58集团签署股权协议
【微信小程序开发】生命周期与生命周期函数
Progressive Web App(PWA)
vue element form表单规则校验 点击提交后直接报数据库错误,没有显示错误信息
刷题《剑指Offer》day07
VMware下安装win10
Flink1.15 source code reading - PER_JOB vs APPLICATION execution process
状态机动态规划之股票问题总结
loadrunner脚本--添加检查点
Mysql+Navicat for Mysql
刷题《剑指Offer》day05
Hematemesis summarizes thirteen experiences to help you create more suitable MySQL indexes