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 ...
随机推荐
- HDU 4858 项目管理(邻接表 暴力模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...
- 用Prime31实现Google Play In-App-Blling
Android开发者想在海外赚钱,接入Google Play是不二选择,然而一堆英文文档对于像我这样的英语四级都木有过的可谓是苦恼之极.近段时间因工作需要研究了Unity接入Google Play的整 ...
- Rotate bitmap by real angle
tl;dr; Use GDI+ SetWorldTransform With WinAPI's SetWorldTransform you can transform the space of dev ...
- Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry has been closed.
现象:更换android studio libs文件夹下的jar包,重新编译代码报错:Cannot locate factory for objects of type DefaultGradleCo ...
- wordpress工作原理
WP初始化的过程:当你输入<yourlink>/wordpress对wordpress进行初始化时,wordpress默认会找根目录下的index.php页面,看一下index.php页面 ...
- 【Django】Django 如何实现 如下 联表 JOIN 查询?
SQL语句: select distinct a.device_hash, sum(b.cmn_merge_count) from (select distinct device_hash from ...
- Merge Two Sorted Arrays
Merge two given sorted integer array A and B into a new sorted integer array. Example A=[1,2,3,4] B= ...
- 基于centos搭建nginx+uwsgi运行django环境
环境: CentOS 7 nginx/1.9.12 Python 2.7.5 一:安装依赖包5 yum install zlib-devel bzip2-devel pcre-devel openss ...
- Gym 100851E Easy Problemset (模拟题)
Problem E. Easy ProblemsetInput file: easy.in Output file: easy.outPerhaps one of the hardest problems ...
- 有时间测试dism
dism /capture-image /imagefile:d\win.win /capturedir:c:\ /name:win81 dism /export-image /winboot /so ...