Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这道题怎么老wa,直接乘应该可以过的,题目说最后结果不会超过long,用__int64应该不会超吧

Posted by tianya at 2005-05-12 11:54:38 on Problem 1306
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator