Polygon for the Angle CF1096C
阿新 • • 發佈:2019-01-01
http://codeforces.com/problemset/problem/1096/C
題意 給你N個數從1N,圍成一圈,給你個K,從1開始,每次跳躍K個,最終回到1,求遇到數的和,遞增輸出所有K時的和
思路 N為1e9,暴力直接跑超時,可以想到找到有個數,整除後另一個是也是可以的,所有開更號就可以了。
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[100005]; int main() { ll n,i,j,p=0; scanf("%lld",&n); for(i=1; i<=sqrt(n); i++) { if(n % i == 0) { ll x = n / i; ll y = x + x*(x-1)/2*i; ans[p++] = y; if(x != i) { y = i + i*(i-1)/2*x; ans[p++] = y; } } } sort(ans,ans+p); for(i=0; i<p; i++) { if(i) printf(" "); printf("%lld",ans[i]); } return 0; }