LightOJ1278 Sum of Consecutive Integers 素数筛法+数学分析

远程桌面项目 阅读详情

Description
Given an integer N, you have to find the number of ways you can express N as sum of consecutive integers. You have to use at least two integers.
For example, N = 15 has three solutions, (1+2+3+4+5), (4+5+6), (7+8).
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with a line containing an integer N (1 ≤ N ≤ 1014).
Output
For each case, print the case number and the number of ways to express N as sum of consecutive integers.
Sample Input
5
10
15
12
36
828495
Sample Output
Case 1: 1
Case 2: 3
Case 3: 1
Case 4: 2
Case 5: 47

题意是给出一个数n,求出有多少种连续整数和等于n(连续整数至少两个)。

我们由 n = a + ( a + 1 ) + ( a + 2 ) + ( a + 3 ) + …… + ( a + k - 1 )  => n = ( 2a + k -1) / 2 * k  =>2n / k - k = 2a - 1  => 2n / k - k 是一个奇数。

如果k是一个偶数,那么2n/k必是奇数,偶数/偶数=奇数;

如果k是一个奇数,那么2n/k必是偶数,偶数/奇数=偶数。

最后可以得到,对于n = 2^a1 * 3^a2 * 5^a3 * 7^a4 * --- * pri^an,计算结果就是 (a2+1) * (a3+1) * (a4+1) * -- * (an+1) - 1。


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
#define maxn 10000005

int prime[700000],c;
bool v[maxn];
void p()
{
    LL i,j,n=maxn,m;
    c=0;
    m=(LL)sqrt(n+0.5);
    memset(v,false,sizeof(v));
    for(i=2;i<=m;i++)
        if(!v[i]){
            for(j=i*i;j<=n;j+=i)
                v[j]=1;
        }
    for(j=2;j<=n;j++){
        if(!v[j]){
            prime[c++]=j;
        }
    }
}

int main()
{
    int t;
    LL l;
    p();
    scanf("%d",&t);
    for(int i=1;i<=t;i++){
        cin>>l;
        while(l%2==0){
            l/=2;
        }
        LL cc=1;
        for(int j=1;j<c;j++){
            if(l==1){
                break;
            }
            if(l%prime[j]==0){
                int s=0;
                while(l%prime[j]==0){
                    l/=prime[j];
                    s++;
                }
                cc*=s+1;
            }
        }
        if(l>1){
            cc*=2;
        }
        printf("Case %d: %lld\n",i,cc-1);
    }
    return 0;
}


工业相机,大恒,面振相机8脚电源线和I/O触发接口线,颜色和接法说明和触发软件设定 上图: 说明一下,工业相机有TTL逻辑电平触发,也有光耦触发等。 这里一般我们用电路板驱动,就用GPIO触发模式, 这里,准备了两个GPIO触发模式,为LINE2,LINE3都可以选择,然后有一个GPIO_GND 如果,你只有一个触发接口,那么如图,选两个就好了。 实际接法如图。 ... 阅读详情

相关推荐

LabView实战:精准实现float到十六进制的转换与高低位拆分

本文详细讲解了在LabVIEW中实现单精度浮点数(float)到十六进制字符串转换,并进行高低16位拆分的实战方法。针对工业通信中设备协议要求,核心使用强制类型转换(Type Cast)获取内存原始数据,避免数值转换错误,并提供了完整的VI构建步骤、交叉验证技巧及常见踩坑经验(如字节序、字符串格式),确保数据通信的准确性。

assembly8low的博客 1772

Sum of Consecutive Integers(有些数学思想)

Given an integer N, you have to find the number of ways you can express N as sum of consecutive integers. You have to use at least two integers. For example, N = 15 has three solutions, (1+2+3+4+5), (...

booty 884

SRC漏洞挖掘实战指南:从零入门到月入过万的网络安全副业

网络安全的核心在于识别和修复系统缺陷,其中逻辑漏洞与信息泄露是常见的安全风险。其原理在于应用程序在业务逻辑设计或数据处理过程中存在缺陷,导致未授权访问或敏感数据暴露。掌握这些技术对于构建安全的应用体系至关重要,不仅能有效防范攻击,也为安全研究人员提供了将技术能力变现的合法途径。在漏洞赏金(Bug Bounty)和SRC(安全应急响应中心)等应用场景中,白帽子通过系统化的测试方法,挖掘此类漏洞,既能获得经济回报,又能积累宝贵的实战经验。本文聚焦于逻辑漏洞与信息泄露的实战挖掘技巧,为初学者提供清晰的入门路径和效

weixin_28568819的博客 363

LightOJ 1278 - Sum of Consecutive Integers (求一个数能被分解为等差数列的方案数)

1278 - Sum of Consecutive Integers   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given an integer N, you have to fi

滴水穿石,慢慢积累,总会有成果 775

万象RK3506-EG1800网关使用说明

摘要:HD-RK3506-EG1800是一款高性能工业物联网边缘计算网关,支持Buildroot和Ubuntu双系统。文档详细介绍了网关的网络配置(包括ETH0/ETH1的静态IP设置、WiFi连接)、时钟同步、HSL软件安装配置(含开机自启动服务)、系统日志优化以及刷机操作指南(Loader/Maskrom模式)。特别提供了基于lighttpd的网页管理方案,通过HTML界面实现网络参数可视化配置,包含身份验证、实时状态显示和表单提交功能。网关默认ETH0固定IP为192.168.1.10,提供完整的CL

tian_jiangnan的博客 192

手把手教你用微信小程序实现智能硬件音视频通话(含Linux/RTOS适配)

本文详细介绍了如何利用微信小程序硬件框架(WMPF)和音视频SDK,在智能硬件(包括Linux与RTOS设备)上实现音视频通话功能。文章从架构设计、设备端SDK集成、小程序VOIP插件开发到跨平台调试与性能优化,提供了全链路实战指南,帮助开发者打通微信小程序与嵌入式设备间的实时音视频通信。

ooo22的博客 357

【LightOJ - 1278】 Sum of Consecutive Integers 【简单公式变形-算数基本定理】

Given an integer N, you have to find the number of ways you can express N as sum of consecutive integers. You have to use at least two integers. For example, N = 15 has three solutions, (1+2+3+4+5), ...

lzs_lazy 525

SpringBoot3项目实战:5分钟搞定Knife4j接口文档配置(含中文版设置)

本文详细介绍了在SpringBoot3项目中快速整合Knife4j接口文档工具的实战教程。内容涵盖核心依赖选择、基础配置、中文界面设置、API信息深度定制以及生产环境安全策略,帮助开发者高效构建专业、可交互的API文档门户,提升团队协作效率。

weixin_29204121的博客 264

UVA11254 Consecutive Integers【暴力】

Any positive integer can be written as the sum of several consecutive integers. For example, 15 = 1 + . . . + 5 = 4 + . . . + 6 = 7 + . . . + 8 = 15 + . . . + 15     Given a positi...

海岛Blog 1157

ProcessingJoy —— 最简单的实时流体模拟【JAVA】

实现基于非常非常经典的 Paper ——Jos Stam 的Real-Time Fluid Dynamics for Games 代码和注释 float visc = 0.0f; float diff = 0.0f; int N = 250; int size = (N + 2) * (N + 2); float[] u = new float[size]; // 速度, 水平/竖直 float[] v = new float[size]; float[] u_prev = new fl...

ShaderJoy 的兴趣技术杂货铺 2825

conda upgrade出现Solving environment:failed CondaValueError Malformed version string invalid chars解决方案

本文主要介绍了conda install出现Solving environment:failed、CondaValueError: Malformed version string invalid character(s),希望能对使用conda的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案 2.1 步骤一 2.2 步骤二

weixin_43178406的博客 8万+

LightOJ 1278 Sum of Consecutive Integers数论

我可算发现了数论啊~就是导啊导啊~~ 设n可以写成a,a+1,a+2……a+k-1的和(其中a>=1),即n=(a+a+k-1)*k/2。那么2a-1=2n/k-k。所以2n/k-k为奇数(分析一下发现k为偶数与题设矛盾)n的一个奇素因子对应一个解,这么想来,素因子这玩意只有2 是偶数,那么根据a=p1^r1*p1^r2*p3^r3……pk^rk n的因子的排列组合就是(p1+1)*(p2+

MissZhou要努力 1118

YOLO26改进 - SPPF模块 | 发论文神器!LSKA注意力改进SPPF,增强多尺度特征提取能力,高效涨点!!!

本文介绍了Large Separable Kernel Attention (LSKA)模块及其在YOLO26中的结合应用。LSKA旨在解决Visual Attention Networks (VAN)使用大内核卷积时的计算效率问题,通过将2D深度卷积层的卷积核分解为级联的水平和垂直1-D卷积核,降低了计算复杂度和内存占用,且使VAN更关注物体形状。我们将集成LSKA的SPPF_LSKA模块引入YOLO26,大量实验表明,改进后的模型在对象识别、检测、分割和稳健性测试上表现出色。

魔改工程师的博客 262

Light OJ 1278 Sum of Consecutive Integers N拆分成连续整数和

题目来源:Light OJ 1278 Sum of Consecutive Integers 题意:N拆分成连续整数和的方案数 思路:奇因数的个数 #include #include #include #include using namespace std; //筛素数 const int maxn = 10000010; bool vis[maxn]; int prime[10

嗯。 1251

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

永远不可能学会的数论之基础数论(例题)

涉及到知识 1.普通筛选、埃拉托斯特尼筛选、欧拉筛选                                            Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach f...

月殇 3154

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Sum of Consecutive Integers—数论 推特点

题目链接:http://lightoj.com/volume_showproblem.php?problem=1278 题意:给你一个数n(n&lt;=10^14),然后问n能用几个连续的数表示; 例如: 15 = 7+8 = 4+5+6 = 1+2+3+4+5,所以15对应的答案是3,有三种;   我们现在相当于已知等差数列的和sum = n, 另首项为a1,共有m项,那么am = a1...

qq_41049928的博客 334

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

UVA Sum of Different Primes (数论+dp)

题意:给出一个数,用k个不同的素数组成他,素数不能重复,求有多少种方法 分析:首先打一个表,然后用类似01背包的方法来写 dp[i][j]表示的是数字i用j个数字来组成的方法数,状态转移方程如下 dp[i][j] = sum{dp[i-prime][k-1]}; for(int i=0;i&lt;tot;i++){ for(int j=maxn-1;j&gt;=prime...

Insist_77的博客 270

LightOJ - 1278 Sum of Consecutive Integers 素质因子

题意: 求连续的一段数字和是给定的n 的组合种数 思路: 自己推一下就可以知道, n 的奇数因子都能提供一个组合方式 那样就转化为求 n 的素质因子的组合方式 #include #include #include #include #include #include #include #include #include #include #include #define PI a

床前明月光 373

LightOJ - 1278 Sum of Consecutive Integers

Given an integer N, you have to find the number of ways you can express N as sum of consecutive integers. You have to use at least two integers. For example, N = 15 has three solutions, (1+2+3+4+5),...

hpu风之旅 317

LIGHT OJ 1278 Sum of Consecutive Integers [因子个数]【数论】

题目链接:http://vjudge.net/contest/137260#problem/W ———————————–. Sum of Consecutive Integers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluDescription Given an integer N, y

Tabris的博客 1037

PAT 乙级 常用输入方式

1.参考:1016 部分A+B(15分) 1.多个数字输入 scanf("%d%d%d%d",&a,&da,&b,&db); 2.字符串跟数字一起输入 string a,b; int da,db; cin>>a>>da>>b>>db; 3.字符数组跟字符(数字)一起输入,带空格 char a[20],b[20]; char da,db; scanf("%s %c %s %c",a,&da,b,&db);

小岛上的盛夏的博客 368

UVa 11254 - Consecutive Integers

题目 一个整数n可以可以被分解成连续的整数的和,求最长的分解。 分析 数学,枚举。 取p #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;math.h&amp;gt; int main() { int n, A, B; while (~scanf(&quot;%d&quot;, &

小白菜又菜 643

UVALive6929 Sums【数学】

Given an integer N, express it as the sum of at least two consecutive positive integers. For example: • 10 = 1 + 2 + 3 + 4 • 24 = 7 + 8 + 9 If there are multiple solutions, output the one with the

海岛Blog 985

ACM-数论-唯一分解定理 Sum of Consecutive Integers

连续的数(n>2)相加的和等于m,求这个连续的数模式的种数 样例:Input Input starts with an integer T (≤ 200), denoting the number of test cases.Each case starts with a line containing an integer N (1 ≤ N ≤ 1014).Output For each cas

CS_W98的博客 834

杭电ACM——6512,Triangle(暴力 / 思维)

这道题是道思维题,但也很特别,有点套路人。把数据弄得很大,让你以为暴力没法解决,就去想方设法去做,结果呢,暴力直接就过了,它所准备的样例遍历几组数据就可以过了,不用遍历出所有情况。 具体原理可参考以下博客: https://blog.csdn.net/sugarbliss/article/details/89438316 代码如下: #include<cstdio> #include&...

shamansi99的博客 526

SPOJ Equation :求 1/n!=1/x+1/y 的解的个数

Description You are given integer positive number N. Find the number of solutions in positive integer numbers of the following equation: 1/N! = 1/X + 1/Y Input Each line of input fil

duanxian0621的专栏 3334
上一篇: LightOJ1215 Finding LCM
下一篇: LightOJ1045 Digits of Factorial 求n的阶乘在k进制下的位数
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址