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 ...
随机推荐
- mac安装最新版本的git
文章转载自我的个人博客 http://www.iwangzheng.com/ 1.下载一个安装包哦 在mac下安装git,首先下载一个git安装包,这里我选的是git-1.9.3.tar , 因为这是 ...
- Cocos2d坐标系转换
Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...
- [BZOJ2724][Violet 6]蒲公英
[BZOJ2724][Violet 6]蒲公英 试题描述 输入 修正一下 l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1 输出 输入示 ...
- lvs之ip-tun(ip隧道)技术的学习与实践
1.配置测试环境 修改IP windows 200.168.10.4 lvs server ip:200.168.10.1 因为IP隧道模式只需要一个网卡 所以就停掉其他网卡 web server ...
- CSS3.0盒模型display:-webkit-box;的使用
box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典 的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没 ...
- PHP 遍历目录
$dir = $_SERVER['DOCUMENT_ROOT'].'/test'; //var_dump($dir);exit; function my_scandir($dir) { $files ...
- 【云计算】mesos生态系统
以 Apache Mesos 计算的开源数据中心 数据中心 易云 · 2015-09-15 16:53 Apache Mesos 是一个管理器,它通过分布式的应用或框架提供了一种高效的资源隔离和共享. ...
- Python DBUtils
1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...
- python模拟浏览器保存Cookie进行会话
#! /usr/bin/env python # -*-coding:utf- -*- import urllib import urllib2 import cookielib class NetR ...
- 利用jQuery.validate异步验证用户名是否存在
转:http://www.cnblogs.com/linzheng/archive/2010/10/14/1851781.html HTML头部引用: <script type="te ...