ural 1268. Little Chu
1268. Little Chu
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
4 |
2 |
Problem Source: Ural State University championship, October 25, 2003
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
bool Visit[N];
int Prime[N], Tot;
int n; inline void GetPrime()
{
For(i, , N - )
{
if(!Visit[i]) Prime[++Tot] = i;
For(j, , Tot - )
{
if(i * Prime[j] > N - ) break;
Visit[i * Prime[j]] = ;
if(!(i % Prime[j])) break;
}
}
} inline void Solve(); inline void Input()
{
GetPrime();
int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--)
{
scanf("%d", &n);
Solve();
}
} inline int Power(int y, int Times)
{
LL Ret = , x = 1LL * y;
while(Times)
{
if(Times & ) Ret = (Ret * x) % n;
x = (x * x) % n, Times >>= ;
}
return Ret;
} inline void Solve()
{
static int Arr[N], Len;
Len = ;
int Tmp = n - ;
For(i, , Tot)
{
if(Tmp < Prime[i]) break;
if(!(Tmp % Prime[i]))
{
Arr[++Len] = Prime[i];
while(!(Tmp % Prime[i]))
Tmp /= Prime[i];
}
}
if(Tmp > ) Arr[++Len] = Tmp; Ford(Ans, n - , )
{
bool Flag = ;
For(i, , Len)
if(Power(Ans, (n - ) / Arr[i]) == )
{
Flag = ;
break;
}
if(!Flag)
{
printf("%d\n", Ans);
break;
}
}
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("D");
#endif
Input();
//Solve();
return ;
}
ural 1268. Little Chu的更多相关文章
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- /run/systemd/private: No such file or directory
今天执行consul脚本的时候报错 /run/systemd/private: No such file or directory reboot -f 重启电脑private文件就出现了.
- [Effective JavaScript 笔记]第37条:认识到this变量的隐式绑定问题
CSVReader示例 需求 CSV(逗号分隔型取值)文件格式是一种表格数据的简单文本表示 张三,1982,北京,中国 小森,1982,东京,日本 吉姆,1958,纽约,美国 现需要编写一个简单的.可 ...
- Powershell学习之道-文件夹共享及磁盘映射
导读 在Linux环境下,我们很轻易就能得心应手地通过命令操作一切事物,在Windows下,Powershell也算是后起之秀,提供大量的cmdlet以及c#的横向拓展.下面将由小编带领大家通过Pow ...
- poj3026(bfs+prim)
The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. ...
- Android程序启动程序与页面的跳转
package login; import com.example.login.R; import android.app.Activity; import android.content.Inten ...
- 经典的SQL面试题
SQL中 inner join. left join .right join. outer join之间的区别 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 ...
- Ubuntu删除history记录
history -c就是清除本次登录到目前所执行的命令 转自: http://www.linuxdiyf.com/viewarticle.php?id=189355
- MySQL使用索引的场景及真正利用索引的SQL类型
1. 为什么使用索引 在无索引的情况下,MySQL会扫描整张表来查找符合sql条件的记录,其时间开销与表中数据量呈正相关.对关系型数据表中的某些字段建索引可以极大提高查询速度(当然,不同字段是否sel ...
- static总结
[本文链接] http://www.cnblogs.com/hellogiser/p/static.html [分析] [内存分配方式] 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局 ...
- python scrapy cannot import name xmlrpc_client的解决方案,解决办法
安装scrapy的时候遇到如下错误的解决办法: "python scrapy cannot import name xmlrpc_client" 先执行 sudo pip unin ...