WLSは、整数nは、彼が1に思っている- N Nデジタルこれは2つのグループに分け、それぞれ少なくとも一つの数を有する基、ならびにその二つの数と最大、出力最大公約数の最大公約数。
入力
整数nの入力ライン。
1≤≤N-2、000、000、000
出力
の出力ラインは、整数に答えます。
入力サンプル
6
サンプル出力
7
アイデア:
我々は、nとの和のための合計に1を祈ります、
そして合計は、それぞれSUM1とSUM2 2つのグループに分けています
その後、我々はSUM1 + SUM2を知っている質問の意味=合計
答えは、需要GCD(SUM1、SUM2)最大であり、我々はANSを設定します
私たちは知っているGCDの最大公約数(SUM1、SUM2)= GCD(SUM1、合計)= GCDの性質に応じて(SUM2、合計)
なぜならGCD(X、Y)= GCD(X、X + Y)
だから我々は、方程式を描くことができます。
SUM1 /年+ SUM2 /年=合計/年
ANSはそれが最大の要因の和である、我々は最大のANSだと思う、明らか因子合計です。
その最大の要因の数を見つけるにはどのように?私達はちょうど暴力が最小のX因子、合計/ X = ANSを列挙合計を見つける必要があります。
詳細コードを参照してください。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
ll n;
cin>>n;
if(n==2)
{
return puts("1");
}else
{
ll sum=(n+1ll)*n/2ll;
for(ll i=2ll;;++i)
{
if(sum%i==0)
{
cout<<sum/i<<endl;
break;
}
}
}
return 0;
}
inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}