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 |
这道题怎么老wa,直接乘应该可以过的,题目说最后结果不会超过long,用__int64应该不会超吧#include<iostream> #include<fstream> #include<cmath> using namespace std; int main(){ ifstream cin("tmp.txt"); int m,n; cin>>m>>n; while(m!=0||n!=0){ int i; int s[200]; int j=0; for(i=0;i<n;i++){ s[j++]=m-i; } __int64 res=1; for(i=0;i<n;i++){ //从m到m-n+1里面找到可以被n-i整除的,然后除掉n-i for(j=0;j<n;j++){ if(s[j]%(n-i)==0){ s[j]/=(n-i); break; } } } for(i=0;i<n;i++){ res*=s[i]; } cout<<m<<" things taken "<<n<<" at a time is "<<res<<" exactly."<<endl; //printf("%d things taken %d at a time is %I64d exactly.\n",dm,dn,res); cin>>m>>n; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator