首页 > 其他分享 >HDU 2715 Herd Sums

HDU 2715 Herd Sums

时间:2022-11-09 20:39:41浏览次数:45  
标签:HDU 15 ways Sums number Herd cows consecutive include


Description


The cows in farmer John's herd are numbered and branded with consecutive integers from 1 to N (1 <= N <= 10,000,000). When the cows come to the barn for milking, they always come in sequential order from 1 to N. 

Farmer John, who majored in mathematics in college and loves numbers, often looks for patterns. He has noticed that when he has exactly 15 cows in his herd, there are precisely four ways that the numbers on any set of one or more consecutive cows can add up to 15 (the same as the total number of cows). They are: 15, 7+8, 4+5+6, and 1+2+3+4+5. 

When the number of cows in the herd is 10, the number of ways he can sum consecutive cows and get 10 drops to 2: namely 1+2+3+4 and 10. 

Write a program that will compute the number of ways farmer John can sum the numbers on consecutive cows to equal N. Do not use precomputation to solve this problem. 


Input


* Line 1: A single integer: N 


Output



* Line 1: A single integer that is the number of ways consecutive cow brands can sum to N. 


Sample Input

15


Sample Output



4

枚举区间长度即可

#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll maxn=100005;
int T,n,m,f[maxn],ans;

int main()
{
for (int i=1;i<=30000;i++) f[i]=i*i;
while (~scanf("%d",&n))
{
ans=0;
for (int i=1;f[i]<n+n;i++)
if ((n+n) % i == 0&&(((n+n)/i-i)&1)) ans++;
printf("%d\n",ans);
}
return 0;
}



标签:HDU,15,ways,Sums,number,Herd,cows,consecutive,include
From: https://blog.51cto.com/u_15870896/5838720

相关文章

  • HDU 5339 Untitled
    ProblemDescriptiona and n integers b1,…,bn.Afterselectingsomenumbersfrom b1,…,bn inanyorder,say c1,…,cr,wewanttom......
  • HDU 3760 Ideal Path
    ProblemDescriptionNewlabyrinthattractionisopeninNewLostlandamusementpark.Thelabyrinthconsistsofnroomsconnectedbympassages.Eachpass......
  • HDU 4101 Ali and Baba
    ProblemDescriptionThereisarectanglearea(withNrowsandMcolumns)infrontofAliandBaba,eachgridmightbeoneofthefollowing:1.Empty......
  • HDU 4198 Quick out of the Harbour
    ProblemDescriptionCaptainClearbearddecidedtogototheharbourforafewdayssohiscrewcouldinspectandrepairtheship.Now,afewdayslater,......
  • HDU 2589 正方形划分
    ProblemDescription一个边长为L的正方形可以分成L*L个小正方形.有N个石子放在N个小正方形里,能否将它分成N个正方形,使得每个正方形里恰有一个石子且这N个正方......
  • HDU 3085 Nightmare Ⅱ
    ProblemDescriptionLastnight,littleerriyuehadahorriblenightmare.Hedreamedthatheandhisgirlfriendweretrappedinabigmazeseparately.Mo......
  • HDU 3313 Key Vertex
    ProblemDescriptionYouneedwalkingfromvertexStovertexTinagraph.IfyouremoveonevertexwhichstopsyoufromwalkingfromStoT,thatverte......
  • HDU 3316 Mine sweeping
    ProblemDescriptionIthinkmostofyouareusingsystemnamedofxporvistaorwin7.Andthesesystemisconsistofafamousgamewhatisminesweeping......
  • HDU 3355 Hop — Don’t Walk!
    ProblemDescriptionKERMITTHEFROGisaclassicvideogamewithasimplecontrolandobjectivebutrequiresagooddealofthinking.Youcontrolanani......
  • HDU 3427 Clickomania
    ProblemDescriptionClickomaniaisapuzzleinwhichonestartswitharectangulargridofcellsofdifferentcolours.Ineachstep,aplayerselects("......