結果
| 問題 |
No.1274 楽しい格子点
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-07 22:59:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 733 bytes |
| コンパイル時間 | 795 ms |
| コンパイル使用メモリ | 73,472 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-22 18:44:32 |
| 合計ジャッジ時間 | 1,730 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 57 |
コンパイルメッセージ
main.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main()
| ^~~~
ソースコード
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
long A,B;
pair<long,long>gcd(long a,long b){
if(a<0)a=-a;
if(b<0)b=-b;
if(a<b)swap(a,b);
if(a==b||b==0)return make_pair(a,b);
return gcd(a-2*b,b);
}
main()
{
cin>>A>>B;
double ans=1./4;
if(A||B)
{
pair<long,long>g=gcd(A,B);
if(g.second==0)
{
for(int i=3;;i++)
{
long u=2+g.first*(i-2);
if(u>20)break;
double now=i-1;
for(int j=0;j<u;j++)now/=u;
ans+=now;
}
}
else
{
for(int i=3;;i++)
{
long u=2+2*g.first*(i-2);
if(u>20)break;
double now=(i-2)*2+1;
for(int j=0;j<u;j++)now/=u;
ans+=now;
}
}
}
cout<<fixed<<setprecision(16)<<ans<<endl;
}