题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391

  1. Problem Description
  2. Tina Town is a friendly place. People there care about each other.
  3.  
  4. Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes time as large as its original size. On the second day,it will become times as large as the size on the first day. On the n-th day,it will become n times as large as the size on the (n-)-th day. Tina want to know its size on the (n-)-th day modulo n.
  5.  
  6. Input
  7. The first line of input contains an integer T, representing the number of cases.
  8.  
  9. The following T lines, each line contains an integer n, according to the description.
  10. T≤,≤n
  11.  
  12. Output
  13. For each test case, output an integer representing the answer.
  14.  
  15. Sample Input
  16.  
  17. Sample Output

题意:求(n-1)!对n取模

方法:如果是素数就是n-1,如果不是素数(除了4)都是0,4的结果是2

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <stack>
  6. #include <math.h>
  7. #include <queue>
  8. #include <vector>
  9. using namespace std;
  10. #define N 10010
  11. #define ll long long
  12. #define met(a,b) memset(a,b,sizeof(a));
  13. vector<vector<int> >Q;
  14. int n;
  15. int main()
  16. {
  17. int t;
  18. scanf("%d",&t);
  19. while(t--)
  20. {
  21. int f=;
  22. scanf("%d",&n);
  23.  
  24. if(n==)///特例
  25. {
  26. printf("2\n");
  27. continue;
  28. }
  29. int k=(int)sqrt(n);
  30. for(int i=; i<=k; i++)
  31. {
  32. if(n%i==)
  33. {
  34. f=;
  35. break;
  36. }
  37.  
  38. }
  39.  
  40. if(f)
  41. printf("0\n");
  42. else
  43. printf("%d\n",n-);
  44. }
  45. return ;
  46. }

(hdu)5391 Zball in Tina Town的更多相关文章

  1. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  2. HDU 5391 Zball in Tina Town【威尔逊定理】

    <题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...

  3. hdu 5391 Zball in Tina Town 威尔逊定理 数学

    Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  4. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  5. HDU 5391 Zball in Tina Town (打表,水)

    题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...

  6. hdoj 5391 Zball in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5391 相关数论结论: 威尔逊定理——当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p ...

  7. HDU-5391 Zball in Tina Town

    (n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...

  8. hdu5391 Zball in Tina Town(威尔逊定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...

  9. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

随机推荐

  1. Weka 入门1

    本人也是借鉴网上他人资料.主要介绍使用java调用Weka库. 首先介绍weka,Weka的全名是怀卡托智能分析环境,是基于开源环境的机器学习和数据挖掘软件.我们可以去weka官网下载最新的Weka软 ...

  2. 动态规划:最长上升子序列(LIS)

    转载请注明原文地址:http://www.cnblogs.com/GodA/p/5180560.html 学习动态规划问题(DP问题)中,其中有一个知识点叫最长上升子序列(longest  incre ...

  3. SIP SDP RTSP RTP RTCP webrtc

    rfc1889  rfc2326  rfc3261  rfc3550  rfc3856  rfc6120. SIP SDP RTSP  RTP RTCP,就像他们出现的顺序一样,他们在实际应用中的启用 ...

  4. ffmpeg编解码音频AAC

    本次项目的需求:手机端和PC端共享同一个音视频网络源. 所以编解码需要满足手机上编码和解码原来PC端的音视频流. 这里先封装安卓手机端音频的编解码. 编译工作依然是在linux下 ubuntu 12. ...

  5. map的基本操作函数及含义

    map的基本操作函数:      C++ Maps是一种关联式容器,包含“关键字/值”对      begin()          返回指向map头部的迭代器      clear()        ...

  6. UNITY 打包安卓APK

    1,安装JDK.这个直接下就行了. 2,安装android sdk相关.这个比较蛋疼,官网是被墙的.有些网站的包还是需要访问墙外下载的.关键是找对那个能用的包(对我来说就是不FQ). http://p ...

  7. [React] React Fundamentals: Owner Ownee Relationship

    The owner-ownee relationship is used to designate a parent-child relationship with React components ...

  8. Java基础知识强化之IO流笔记39:字符流缓冲流之复制文本文件案例01

    1. 字符流缓冲流之复制文本文件案例 需求:把当前项目目录下的a.txt内容复制到当前项目目录下的b.txt中 数据源: a.txt -- 读取数据 -- 字符转换流 -- InputStreamRe ...

  9. 功能测试中遇到的一些有意思的bug

    2016.1.25 1.  Xss攻击型的bug Xss攻击即跨站脚步攻击,通过插入恶意脚本 ,实现对用户浏览器的控制. Bug现象:新增物品时,物品名称输入一段JavaScript代码,在提交时此代 ...

  10. windows 下 node 多版本管理工具 - gnvm

    最近写了各个构建工具, 开发环境为mac,需要在windows下测试通过: 因为很久不用windows,windows下的node 版本还是 0.10.* 的,因此决定升级node mac 下我使用的 ...