<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>flashingwind</author_name>
  <author_url>https://blog.hatena.ne.jp/flashingwind/</author_url>
  <blog_title>プログラマーになりたい。</blog_title>
  <blog_url>https://flash.hatenablog.com/</blog_url>
  <categories>
    <anon>AtCoder</anon>
    <anon>今日のバグ</anon>
  </categories>
  <description>要素がu32型のvecの総和を求める際、いつもはfor式を使い、sum()を使わないのだが、ちょっとかっこつけて使ってみたら失敗したという話です。 和を取るとき、オーバーフローするというのはよくあるのだが、sum()にをつけてもダメだった、結果をキャストするだけらしい。今日はこれでハマった。 そもそも、N=109、A[i]=109 (0≦i&lt;N)みたいな、よくある設定がありますが、あれは符号なし32bit整数型(unsigned int/u32)で計算すると桁あふれすることを狙っている場合があります。 今回の計算の場合以下のように見積もると、32bitでは足りない値が出てきました。そこで最後の…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fflash.hatenablog.com%2Fentry%2F2023%2F06%2F05%2F024713&quot; title=&quot;vec&amp;lt;u32&amp;gt;の総和はsum&amp;lt;u64&amp;gt;()でもu32の最大値でオーバーフローする - プログラマーになりたい。&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2023-06-05 02:47:13</published>
  <title>vec&lt;u32&gt;の総和はsum&lt;u64&gt;()でもu32の最大値でオーバーフローする</title>
  <type>rich</type>
  <url>https://flash.hatenablog.com/entry/2023/06/05/024713</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
