posts - 195,  comments - 30,  trackbacks - 0

求模的思想
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;

  int main()
  {
  //freopen("s.txt","r",stdin);
  //freopen("key.txt","w",stdout);
  int n;
  int temp;
  while(cin>>n)
  {
  cout<<setw(5)<<n<<" -> " ;
  temp=1;
  for(int j=1;j<=n;j++)
  {
   int i=j;
   while(i%10==0)
   {
    i/=10;
   }
   while(i%5==0)
   {
    i/=5;
    temp/=2;
   }
   
   temp*=i;
   
  //¼ÆËãĩλ
   temp%=100000;
  }
  while(temp%10==0)
  temp/=10;
  temp%=10;
  cout<<temp<<endl;
  }

  //system("PAUSE");
  return   0;
  }
一种是分类的思想

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
 long a[10001]={0,1,2,6,4,2},b[5]={0,2,4,8,6},i,m,n;
 for(i=6;i<=10000;i++)
 {
  m=i%5;
  n=i/5;
  if(m!=0)
   a[i]=a[i-1]*i%10;
  else
   a[i]=b[(n-1)%4+1]*a[n]%10;
 }
 while(cin>>n)
  cout<<setw(5)<<n<<" -> "<<a[n]<<endl;
 return 0;
}

posted on 2009-07-08 10:45 luis 阅读(315) 评论(0)  编辑 收藏 引用 所属分类: 格式.输入输出.数据类型

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年1月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜