Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请问大牛:这道题输入21应该输出什么?我觉得应该输出3 21=21 21=10+11 21=6+7+8 答案21=0+1+2+3+4+5+6应该是不对的。 下面有两段代码, 第一段代码是我同学做的,我用mj试过,这段程序是能够AC的,但是输入21,输出是4 第二段是我的程序,对于数据21,输出是3,我觉得没错,但是wa了,请教大牛,怎么回事? /*********代码1**************/ #include <stdio.h> int main() { int n,i,ways; while(scanf("%d",&n)!=EOF) { ways = 0; if(n%2 != 0)ways++; for(i = 1;i < n;i = i + 2) { if(n%i == 0) ways++; } printf("%d\n",ways); } return 0; } /************代码2************/ #include <stdio.h> main() { long n; long i; long num; while(scanf("%ld",&n)!=EOF) { num=0; for(i=0;i*(2*i+1)<=n;i++) if(n%(2*i+1)==0 && n/(2*i+1)>i) num++; i=1; while((n/i)%2==0) { i=i*2; } if(n/i>2*i) num++; printf("%ld\n",num); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator