poj 1183(数学推导,参考https://blog.csdn.net/dumeichen/article/details/47951553)

#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int main(){
    ll a,m,n;
    scanf("%lld",&a);//b = a+m,c = a+n,mn = a*a+1
    for(m=a;m>=1;m--)
        if((a*a+1)%m==0) {
            break;
        }
    n = (a*a+1)/m;
    printf("%lld\n",a*2+m+n);
    return 0;
} 

 

上一篇:【P2169 正则表达式】题解


下一篇:POJ prime distance