Lightoj 1278-sum of consecutive integers (number of odd factors)

Source: Internet
Author: User



Title Link: http://lightoj.com/volume_showproblem.php?problem=1278



Test instructions: give you a number n (n<=10^14), then ask N can be expressed in several consecutive numbers;



For example: 15 = 7+8 = 4+5+6 = 1+2+3+4+5, so 15 corresponding answer is 3, there are three kinds;






We are now equivalent to known arithmetic progression and sum = N, the other first item is A1, Total m, then am = a1+m-1;



sum = m* (a1+a1+m-1)/2-----> a1 = sum/m-(m-1)/2



A1 and M must be integers, so sum%m = 0 and (m-1)%2=0, so M is the factor of sum, and if odd;






So we only ask for the number of the odd factor of N, and the number of factors is the number of all prime factors of the power +1, multiplied by, then only 2 of the primes are even,



So the number of odd factor is all the prime factor (except 2) +1 of the product, of course, M must be greater than 1, so subtract 1, remove factor 1 case;





'35; include <stdio.h>
'35; include <iostream>
'35; include <algorithm>
%35; include <string.h>
using namespace std;
typedef long long LL;
const double eps = 1e-10;
const int N = 1e7+1;
int p[N/10], k;
bool f[N];
void Init()
{
for(int i=2; i<N; i++)
{
if! f[i]) p[k++] = i;
for(int j=i+i; j<N; j+=i)
f[j] = true;
*
*
int main()
{
Init();
int T, t = 1;
scanf("%d", &amp;T);
while(T --)
{
LL n, as = 1;
scanf("%lld", &amp;n);
int flag = 0;
for(int i=0; i<k &amp;&amp;LL)p[i]*p[i]<=n; i++)
{
LL cnt = 0;
while(n%p[i] == 0)
{
cnt ++;
n /= p[i];
*
if(i)///19981;- 33021;- 31639; 2
ans *= cnt+1;
*
if(n > 2)
to *= 2;
ans -= 1;///20943;- 21435;- 1d209171;
printf("Case%d:%lld\n", t++, ans);
*
return 0;
* 
View Code





Lightoj 1278-sum of consecutive integers (number of odd factors)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.