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

题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种。

思路:先列式子\(N=a+(a+1)+(a+2)+ ...+(a+k-1)=\frac{k·(2a+k-1)}{2} \) 继续化成\(2a-1=\frac{2N}{k} - k \) 可由左式得知,2a-1必为奇数,那么右式必定是一奇一偶,且都为2N的因子。所以只要分解因子记录个数,最后组合求一下即可。

/** @Date    : 2016-11-24-22.15* @Author  : Lweleth (SoungEarlf@gmail.com)* @Link    : https://github.com/* @Version :*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include<bits/stdc++.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;const int INF = 0x3f3f3f3f;
const int N = 1e6+20;
int pri[670000];
int c = 0;
bool vis[N*10];void prime()
{MMF(vis);for(int i = 2; i < N*10; i++){if(!vis[i])pri[c++] = i;for(int j = 0; j < c && i * pri[j] < N*10; j++){vis[i*pri[j]] = 1;if(i % pri[j] == 0)break;}}
}int main()
{int T;int cnt = 0;cin >> T;prime();while(T--){LL n;scanf("%lld", &n);LL ans = 1;//while(n % 2 == 0)//    n/=2;for(int i = 0; i < c && pri[i]*pri[i] <= n; i++)//记录素因子为奇数的(除2外的) {LL ct = 0;while(n % pri[i] == 0){if(i != 0)ct++;n /= pri[i];}ans *= (ct + 1);}if(n > 1 && n != 2){ans *= 2;}printf("Case %d: %lld\n", ++cnt, ans-1);}return 0;
}

转载于:https://www.cnblogs.com/Yumesenya/p/6123939.html

LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维相关推荐

  1. lightOJ 1278

    lightOJ 1278 题意:求一个数可以写成多少种连续数相加的形式, 如15可以写成(7+8)(4+5+6)(1+2+3+4+5)共三种 思路:设 N = a[1]+a[2]+--+a[m]; N ...

  2. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  3. leetcode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  4. sum of two integers

    https://leetcode.com/problems/sum-of-two-integers/ Calculate the sum of two integers a and b, but yo ...

  5. LeetCode之Sum of Two Integers

    1.题目 Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

  6. Leetcode PHP题解--D84 371. Sum of Two Integers

    D84 371. Sum of Two Integers 题目链接 371. Sum of Two Integers 题目分析 相加给定的两个数,但不能使用+或-运算符. 思路 可以用二进制的与运算完 ...

  7. C#LeetCode刷题之#371-两整数之和(Sum of Two Integers)

    问题 不使用运算符 + 和 - ,计算两整数 a .b 之和. 输入: a = 1, b = 2 输出: 3 输入: a = -2, b = 3 输出: 1 Calculate the sum of ...

  8. AOJ0008 Sum of 4 Integers【暴力】

    Sum of 4 Integers Aizu - 0008 Write a program which reads an integer n and identifies the number of ...

  9. leetcode17 Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Examp ...

最新文章

  1. 申请信用贷款需要哪些条件?
  2. c语言年历表程序设计,c语言程序设计年历显示-20210413153548.docx-原创力文档
  3. mysql mrr cost based,MySQL InnoDB MRR 优化
  4. WebLogic 11g重置用户密码
  5. 计算机的声卡怎么安装教程,图文详解如何安装声卡驱动_给电脑安装声卡驱动的详细教程...
  6. 【考研】数据库知识点总结
  7. 视频加密大全服务条款
  8. 解决 Git 报错:GitHub - failed to connect to github 443
  9. window磁盘id与序列号
  10. 精灵复兴 与服务器链接中断,精灵复兴一键服务端+视频架设教程+GM模式介绍+2036合成公式+客户端...
  11. 定义一个抽象类一水果,创建若干水果对象存放在-一个水果类型的数组中,输出数组中所有水果的类型、重量
  12. linux PPPOE拨号上网设置
  13. 生物传感器相关概念简述(一)
  14. 如何可以把模糊的照片变得高清?
  15. 面向6G网络自动化的知识驱动可解释人工智能(XAI);基于汽车事件数据的脉冲神经网络目标检测;对称分类方案下波导阵列中的BIC;PreMovNet:基于运动前脑电的抓取和提举手运动学估计
  16. Ubuntu系统无线网卡驱动一键安装(告别繁琐安装和盲目安装)
  17. 最新用友U8V15.0全产品培训视频教程合集
  18. 扫描探针显微术入门(2 消除各种外界干扰的措施)
  19. matlab绘制极限环,常微分方程组的MATLAB求解方法
  20. 行测-判断推理-图形推理-样式规律-数量规律-面数量

热门文章

  1. oracle服务开机自启动
  2. 输入输出Fibonacci数
  3. 香港科技大学(广州)智能交通学域招收博士/RA 22Fall, 23 Spring/Fall
  4. 计算机比特块的输出概念,第1讲-比特的概念及计算机的组成原理.ppt
  5. 3D Vision公开课 | 移动机器人视觉三维感知的现在与将来
  6. 推荐系统遇上深度学习(二)--FFM模型理论和实践
  7. 深度学习(五十五)tensorflow分布式训练
  8. 华为服务器改硬盘启动不了怎么办,华为服务器装系统加载os怎么回事
  9. matlab 正则化表达式_MATLAB 正则表达式(一)(转)
  10. windows更改pip源_让你的 pip下载速度 飞起来