- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题的链接是 - spoj question
我尝试通过这种方法解决问题 - N 范围内的对数 = N-1 范围内的对数 + 一些新对。
但我不知道这里还应该做哪些优化来避免 TLE。我还阅读了有关 euler totient 函数的内容,但无法真正理解该方法。我已经阅读了 4 种计算 euler phi 的方法,但我猜它们都需要相同的 O(n^2)。
P.S - 我只想知道有关进一步方法而不是直接解决方案的提示。提示就可以了。预先非常感谢。
这个问题的代码是 -
#include<stdio.h>
typedef unsigned long long int ull;
ull a[100000] = {0};
inline ull g()
{
ull n=0;
char ch;
ch = getchar_unlocked();
while(ch < '0' || ch > '9')
ch = getchar_unlocked();
while(ch >= '0' && ch <= '9') {
n = (n<<3) + (n<<1) + (ch - '0');
ch = getchar_unlocked();
}
return n;
}
ull gcd( ull a , ull b)
{
if(b == 0)
return a;
else
return gcd(b , a % b);
}
ull find(ull n)
{
if(n == 0 || n == 1)
return n;
else if(a[n] != 0)
return n;
else
return find(n-1);
}
ull range(ull n)
{
ull c, i, nf,t;
nf = find(n);
c = a[nf];
t = nf;
nf++;
while(nf <= n) {
a[nf] = a[t];
for(i = 2 ; i <= nf ; i++) {
ull gd = gcd(i,nf);
if(gd > 1) {
c++;
a[nf]++;
}
}
nf++;
}
return c;
}
int main()
{
ull t = g();
ull i = 1;
while(t--) {
ull n = g();
if(a[n] == 0)
a[n] = range(n);
printf("Case %llu: %llu\n",i++,a[n]);
}
return 0;
}
最佳答案
去尝试一下,就得到了空调。
正如您所说的仅提示,这里有一些基于我的 AC 解决方案和您的尝试:
O(n^2)
?真的吗?至少在我的代码中,我不认为它是O(n^2)
GCD
函数n
进行循环,您可以在O(1)
中输出答案!关于c - spoj NAJPWG 的解决方案。给予 TLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30719091/
我试图让 UIScrollView 的末端淡出 - 就像 UITableView 一样。我找到了下面的代码。我在 UIScrollView 子类中的 initWithFrame:... 内部调用的方法
很抱歉为此打扰你,但我可能已经为这个问题生气了 5 个小时,但我没能解决它。 我有一个包含大约 37,000 个条目的数据集。它们每个都有自己的 Lon 和 Lat 坐标值。检查整体值,它们的范围分别
我目前有一个表格 View ,其中有单元格 View ,其中包含 NSTextFields。目前,在行选择时,我向单元格 View 发送以下消息,希望授予单元格 View 中的 NSTextView
我在我的应用程序中使用 NSUserDefaults 来存储一些标志值。每次发生条件时,我的函数都会增加值。偶尔它可以工作,但大多数时候它会崩溃并收到 EXC_BAD_ACCESS 消息。 var s
我是 bootstrap 的新手并且很喜欢它。但是,我有一个小问题,我不确定如何解决。为了更好地解释它,我绘制了一个简单的网站布局。 这是网站在普通桌面显示器上的样子 这是网站在手机(iPhone 5
我正在使用 Storyboard ,在我的 Storyboard 中我有一个按钮与另一个 View Controller 相连。所以当你点击按钮时,另一个 View Controller 就会出现。我
我正在与 Stripe 合作。我们的用户订阅了我们的服务,并且每 2 周向他们收费一次。我们需要实现一种方法,在他们每次推荐某人使用我们的服务时给他们 5 美元的信用额度。 到目前为止我考虑过的解决方
我有一个允许用户在 3 个不同 View 之间滑动的 Activity 。每个 View 显示一个图像列表。图像具有调用新 Activity 并使图像全屏显示的 onClick 事件。这一切正常,但是
问题的链接是 - spoj question 我尝试通过这种方法解决问题 - N 范围内的对数 = N-1 范围内的对数 + 一些新对。 但我不知道这里还应该做哪些优化来避免 TLE。我还阅读了有关
我正在创建一个网站,但遇到了问题 - 我的页脚和其余内容之间有很大的空间。我有一个包含我所有内容的容器,包括我的页脚,但是有一个单独的 div 包含该容器中的内容。容器 div 没有设置高度,因为它应
我有一个类似这样的查询 select city_desc from mst_city where upper(city_desc) like upper('%branch%') 它填充结果以分支开头的
我正在开发带有 Web 界面 (apache) 的嵌入式 Linux 系统。基本上,我需要向 Web 界面添加关机和重启功能。但是,我在运行时遇到了权限问题: exec("shutdown now")
我正在考虑验证用户输入的最佳方式。 让我们想象一些 TextBoxes、CheckBoxes 或您喜欢的任何 .NET 控件,其中用户输入必须被验证为 OK 或 NOK。一旦用户填写了所有必填字段,他
首先对不起我的英语,我是德国人。我将 Debian 与 apache2 和 php5 一起使用。该服务器仅用于测试并位于我的本地网络中,因此我没有遇到任何安全问题。我的问题是: 如何给 PHP/PHP
我正在尝试将 Uber SDK 与我当前的 iOS 应用程序集成。 我有 Xcode:- 8.1 iOS:-10.1 和 swift 版本:- 3.0 我已经完成了“Carthage”的 Uber 集
我是一名优秀的程序员,十分优秀!